﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Xml.Serialization;
using Salamanca.DataAccess;
using Salamanca.DataAccess.Collections;
using Salamanca.DataRules;
#if (!NET_CF)
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
#endif

namespace Sevesc.Sps.DomainModel
{



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class LieuDeService:
        DomainEntity<LieuDeService.PrimaryKey, LieuDeService.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="LieuDeService" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="LieuDeService" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="LieuDeService.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="LieuDeService.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid? Client_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid? Adresse_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Statut;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Risque;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Localisation;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Boolean Actif;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public LieuDeService():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="LieuDeService" /> entity.</summary>
        public LieuDeService(DataMapperCollection dataMappers):
            base(dataMappers)
        {
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="LieuDeService" /> entity with serialized data.</summary>
        protected LieuDeService(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadClient(lazyLoad);
                _LoadAdresse(lazyLoad);
                _LoadContrats(lazyLoad);
                _LoadConventions(lazyLoad);
                _LoadCompteurs(lazyLoad);
                _LoadDossiers(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Client=null;
            _Adresse=null;
            _Contrats=null;
            _ContratsAssociation=null;
            _Conventions=null;
            _Compteurs=null;
            _Dossiers=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);

            _LoadContrats(true);
            _ContratsAssociation.Delete(e.Context);

            _LoadConventions(true);
            _Conventions.Delete(e.Context);

            _LoadDossiers(true);
            _Dossiers.Delete(e.Context);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (Client!=null)
                Client.Save(e.Context);

            if (Adresse!=null)
                Adresse.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Contrats!=null)
                _Contrats.Save(e.Context);

            if (_Conventions!=null)
                _Conventions.Save(e.Context);

            if (_Compteurs!=null)
                _Compteurs.Save(e.Context);

            if (_Dossiers!=null)
                _Dossiers.Save(e.Context);
        }

        /// <summary />
        protected override LieuDeService.PrimaryKey CreateId()
        {
            return new LieuDeService.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal LieuDeService.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadClient(bool lazyload)
        {
            if (_Client==null)
            {
                if (IsNew)
                    return;

                if (!Data.Client_Id.HasValue)
                    return;

                _Client=((IPersonneMapper)DataMappers[typeof(Personne)]).Find(Data.Client_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Client" /> internal information.</summary>
        private void _UpdateClient()
        {
            Debug.Assert(!_Client.InternalIsNew);
            if (_Client.InternalIsNew)
                throw new InvalidOperationException("_Client has never been saved.");

            {
                System.Guid? id=(_Client!=null ? _Client.GetId().Value : (System.Guid?)null);
                if (Data.Client_Id!=id)
                    Data.Client_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Client" /> has been saved for the first time.</summary>
        private void _Client_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateClient();
            IsModified=true;
            ((Personne)sender).Saved-=_Client_Saved;
        }

        /// <summary />
        private void _LoadAdresse(bool lazyload)
        {
            if (_Adresse==null)
            {
                if (IsNew)
                    return;

                if (!Data.Adresse_Id.HasValue)
                    return;

                _Adresse=((IAdresseMapper)DataMappers[typeof(Adresse)]).Find(Data.Adresse_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Adresse" /> internal information.</summary>
        private void _UpdateAdresse()
        {
            Debug.Assert(!_Adresse.InternalIsNew);
            if (_Adresse.InternalIsNew)
                throw new InvalidOperationException("_Adresse has never been saved.");

            {
                System.Guid? id=(_Adresse!=null ? _Adresse.GetId().Value : (System.Guid?)null);
                if (Data.Adresse_Id!=id)
                    Data.Adresse_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Adresse" /> has been saved for the first time.</summary>
        private void _Adresse_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateAdresse();
            IsModified=true;
            ((Adresse)sender).Saved-=_Adresse_Saved;
        }

        /// <summary />
        private void _LoadContrats(bool lazyload)
        {
            if (_Contrats==null)
            {
                if (IsNew)
                {
                    _Contrats=new DomainEntityKeyedCollection<Contrat>();
                    _ContratsAssociation=new DomainEntityKeyedCollection<LieuxDeServiceContrats>();
                } else
                {
                    _Contrats=(DomainEntityKeyedCollection<Contrat>)Contrat.FindByLieuxDeService(this, DataMappers);
                    _ContratsAssociation=(DomainEntityKeyedCollection<LieuxDeServiceContrats>)LieuxDeServiceContrats.FindByLieuDeService(this, DataMappers);
                }

                _Contrats.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        if (!((Contrat)e.Element).LieuxDeService.Contains(this))
                            ((Contrat)e.Element).LieuxDeService.Add(this);
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Contrat)e.Element).LieuxDeService.Contains(this))
                            ((Contrat)e.Element).LieuxDeService.Remove(this);
                        break;
                    }
                };

                _Contrats.Saving+=delegate(object s, DomainEntityCollectionSavingEventArgs<Contrat> e) {
                    foreach (Contrat a in e.AddedItems)
                        if (!IsNew && !a.InternalIsNew)
                        {
                            LieuxDeServiceContrats.PrimaryKey pk=new LieuxDeServiceContrats.PrimaryKey(GetId(), a.GetId());
                            try
                            {
                                GC.KeepAlive(_ContratsAssociation[pk]);
                            } catch (KeyNotFoundException)
                            {
                                LieuxDeServiceContrats n=new LieuxDeServiceContrats(this, a, DataMappers);
                                _ContratsAssociation.Add(n);
                                a.LieuxDeServiceAssociation.Add(n);
                            }
                        }
                    foreach (Contrat r in e.RemovedItems)
                        _ContratsAssociation[new LieuxDeServiceContrats.PrimaryKey(Id, r.GetId())].Delete(e.Context);
                };
                _Contrats.Saved+=delegate(object s, PersistenceEventArgs e) {
                    _ContratsAssociation.Save(e.Context);
                };
                _ContratsAssociation.Deleted+=delegate(object s, PersistenceEventArgs e) {
                    _ContratsAssociation.Clear();
                };
            }
        }

        /// <summary />
        private void _LoadConventions(bool lazyload)
        {
            if (_Conventions==null)
            {
                if (IsNew)
                    _Conventions=new DomainEntityKeyedCollection<Convention>();
                else
                    _Conventions=(DomainEntityKeyedCollection<Convention>)Convention.FindByLieuDeService(this, DataMappers);

                _Conventions.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Convention)e.Element).LieuDeService=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Convention)e.Element).LieuDeService==this)
                            ((Convention)e.Element).LieuDeService=null;
                        break;
                    }
                };
            }
        }

        /// <summary />
        private void _LoadCompteurs(bool lazyload)
        {
            if (_Compteurs==null)
            {
                if (IsNew)
                    _Compteurs=new DomainEntityKeyedCollection<Compteur>();
                else
                    _Compteurs=(DomainEntityKeyedCollection<Compteur>)Compteur.FindByLieuDeService(this, DataMappers);

                _Compteurs.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Compteur)e.Element).LieuDeService=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Compteur)e.Element).LieuDeService==this)
                            ((Compteur)e.Element).LieuDeService=null;
                        break;
                    }
                };
            }
        }

        /// <summary />
        private void _LoadDossiers(bool lazyload)
        {
            if (_Dossiers==null)
            {
                if (IsNew)
                    _Dossiers=new DomainEntityKeyedCollection<Dossier>();
                else
                    _Dossiers=(DomainEntityKeyedCollection<Dossier>)Dossier.FindByLieuDeService(this, DataMappers);

                _Dossiers.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Dossier)e.Element).LieuDeService=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Dossier)e.Element).LieuDeService==this)
                            ((Dossier)e.Element).LieuDeService=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="LieuDeService" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static LieuDeService Find(LieuDeService.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((ILieuDeServiceMapper)dataMappers[typeof(LieuDeService)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="LieuDeService" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<LieuDeService> FindAll(DataMapperCollection dataMappers)
        {
            return ((ILieuDeServiceMapper)dataMappers[typeof(LieuDeService)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="LieuDeService" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<LieuDeService> FindByClient(Personne entity, DataMapperCollection dataMappers)
        {
            return ((ILieuDeServiceMapper)dataMappers[typeof(LieuDeService)]).FindByClient(entity, dataMappers);
        }

        /// <summary>Returns the <see cref="LieuDeService" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<LieuDeService> FindByAdresse(Adresse entity, DataMapperCollection dataMappers)
        {
            return ((ILieuDeServiceMapper)dataMappers[typeof(LieuDeService)]).FindByAdresse(entity, dataMappers);
        }

        /// <summary>Returns the <see cref="LieuDeService" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<LieuDeService> FindByContrats(Contrat entity, DataMapperCollection dataMappers)
        {
            return ((ILieuDeServiceMapper)dataMappers[typeof(LieuDeService)]).FindByContrats(entity, dataMappers);
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public Personne Client
        {
            get
            {
                Load(true);
                return _Client;
            }
            set
            {
                _LoadClient(true);
                if (_Client!=value)
                {
                    // If _Client is new, it has been registered for update when being saved for the first time
                    if ((_Client!=null) && (_Client.InternalIsNew))
                        _Client.Saved-=_Client_Saved;

                    if (_Client!=null)
                    {
                        if (_Client.LieuxDeService.Contains(this))
                            _Client.LieuxDeService.Remove(this);
                        
                    }
                    if (!value.LieuxDeService.Contains(this))
                        value.LieuxDeService.Add(this);
                    _Client=value;

                    // If _Client is new, its primary key will only be set after being saved for the first time
                    if ((_Client!=null) && _Client.InternalIsNew)
                        _Client.Saved+=_Client_Saved;
                    else
                        _UpdateClient();

                    RaisePropertyChanged("Client");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public Adresse Adresse
        {
            get
            {
                Load(true);
                return _Adresse;
            }
            set
            {
                _LoadAdresse(true);
                if (_Adresse!=value)
                {
                    // If _Adresse is new, it has been registered for update when being saved for the first time
                    if ((_Adresse!=null) && (_Adresse.InternalIsNew))
                        _Adresse.Saved-=_Adresse_Saved;

                    if (_Adresse!=null)
                    {
                        if (_Adresse.LieuxDeService.Contains(this))
                            _Adresse.LieuxDeService.Remove(this);
                        
                    }
                    if (!value.LieuxDeService.Contains(this))
                        value.LieuxDeService.Add(this);
                    _Adresse=value;

                    // If _Adresse is new, its primary key will only be set after being saved for the first time
                    if ((_Adresse!=null) && _Adresse.InternalIsNew)
                        _Adresse.Saved+=_Adresse_Saved;
                    else
                        _UpdateAdresse();

                    RaisePropertyChanged("Adresse");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Contrat> Contrats
        {
            get
            {
                _LoadContrats(true);
                return new Collection<Contrat>(_Contrats);
            }
        }
        /// <summary />
        internal DomainEntityKeyedCollection<LieuxDeServiceContrats> ContratsAssociation
        {
            get
            {
                _LoadContrats(true);
                return _ContratsAssociation;
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Convention> Conventions
        {
            get
            {
                _LoadConventions(true);
                return new Collection<Convention>(_Conventions);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Compteur> Compteurs
        {
            get
            {
                _LoadCompteurs(true);
                return new Collection<Compteur>(_Compteurs);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Dossier> Dossiers
        {
            get
            {
                _LoadDossiers(true);
                return new Collection<Dossier>(_Dossiers);
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Statut
        {
            get
            {
                Load(true);
                return Data.Statut;
            }
            set
            {
                if (Data.Statut!=value)
                {
                    Data.Statut=value;
                    RaisePropertyChanged("Statut");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Risque
        {
            get
            {
                Load(true);
                return Data.Risque;
            }
            set
            {
                if (Data.Risque!=value)
                {
                    Data.Risque=value;
                    RaisePropertyChanged("Risque");
                }
            }
        }

        /// <summary />
        [StringLengthRule(255)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Localisation
        {
            get
            {
                Load(true);
                return Data.Localisation;
            }
            set
            {
                if (Data.Localisation!=value)
                {
                    Data.Localisation=value;
                    RaisePropertyChanged("Localisation");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.Boolean Actif
        {
            get
            {
                Load(true);
                return Data.Actif;
            }
            set
            {
                if (Data.Actif!=value)
                {
                    Data.Actif=value;
                    RaisePropertyChanged("Actif");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private Personne _Client;

        /// <summary />
        private Adresse _Adresse;

        /// <summary />
        private DomainEntityKeyedCollection<Contrat> _Contrats;
        /// <summary />
        private DomainEntityKeyedCollection<LieuxDeServiceContrats> _ContratsAssociation;

        /// <summary />
        private DomainEntityKeyedCollection<Convention> _Conventions;

        /// <summary />
        private DomainEntityKeyedCollection<Compteur> _Compteurs;

        /// <summary />
        private DomainEntityKeyedCollection<Dossier> _Dossiers;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    internal partial class LieuxDeServiceContrats:
        DomainEntity<LieuxDeServiceContrats.PrimaryKey, LieuxDeServiceContrats.DataTransfer>
    {

        /// <summary />
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        internal partial class PrimaryKey:
            PrimaryKey<PrimaryKey.Key>
        {

            /// <summary>Holds the composite value of the <see cref="LieuxDeServiceContrats.PrimaryKey" /> class.</summary>
            internal struct Key
            {

                /// <summary />
#if (!NET_CF)
                [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
                public System.Guid LieuDeService_Id;

                /// <summary />
#if (!NET_CF)
                [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
                public System.Guid Contrat_Id;

                /// <summary>Creates a new instance of the <see cref="LieuxDeServiceContrats.PrimaryKey.Key" /> class.</summary>
                public Key(System.Guid lieudeservice_id, System.Guid contrat_id)
                {
                    LieuDeService_Id=lieudeservice_id;
                    Contrat_Id=contrat_id;
                }

                /// <summary>Returns a string that represents the current <see cref="LieuxDeServiceContrats.PrimaryKey" />.</summary>
                public override string ToString()
                {
                    return string.Format(
                        CultureInfo.CurrentCulture,
                        "{0}|{1}",
                        LieuDeService_Id,
                        Contrat_Id
                    );
                }
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey(PrimaryKey.Key key):
                base(key)
            {
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey(LieuDeService.PrimaryKey lieudeserviceKey, Contrat.PrimaryKey contratKey):
                base(new PrimaryKey.Key(lieudeserviceKey.Value, contratKey.Value))
            {
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey(Contrat.PrimaryKey contratKey, LieuDeService.PrimaryKey lieudeserviceKey):
                this(lieudeserviceKey, contratKey)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(PrimaryKey.Key key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator PrimaryKey.Key(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        internal partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid LieuDeService_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Contrat_Id;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public LieuxDeServiceContrats():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="LieuxDeServiceContrats" /> association entity.</summary>
        public LieuxDeServiceContrats(LieuDeService lieudeservice, Contrat contrat, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            Debug.Assert(lieudeservice!=null);
            if (lieudeservice==null)
                throw new ArgumentNullException("lieudeservice");
            Debug.Assert(contrat!=null);
            if (contrat==null)
                throw new ArgumentNullException("contrat");

            LieuDeService=lieudeservice;
            Contrat=contrat;
        }

        /// <summary>Creates a new instance of the <see cref="LieuxDeServiceContrats" /> association entity.</summary>
        public LieuxDeServiceContrats(Contrat contrat, LieuDeService lieudeservice, DataMapperCollection dataMappers):
            this(lieudeservice, contrat, dataMappers)
        {
        }

        /// <summary />
        protected override LieuxDeServiceContrats.PrimaryKey CreateId()
        {
            return new LieuxDeServiceContrats.PrimaryKey(new LieuxDeServiceContrats.PrimaryKey.Key(Data.LieuDeService_Id, Data.Contrat_Id));
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (_LieuDeService.InternalIsNew)
                _LieuDeService.Save(e.Context);
            if (_Contrat.InternalIsNew)
                _Contrat.Save(e.Context);
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="LieuDeService" /> internal information.</summary>
        private void _UpdateLieuDeService()
        {
            Debug.Assert(!_LieuDeService.InternalIsNew);
            if (_LieuDeService.InternalIsNew)
                throw new InvalidOperationException("_LieuDeService has never been saved.");

            {
                System.Guid id=_LieuDeService.GetId().Value;
                if (Data.LieuDeService_Id!=id)
                    Data.LieuDeService_Id=id;
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Contrat" /> internal information.</summary>
        private void _UpdateContrat()
        {
            Debug.Assert(!_Contrat.InternalIsNew);
            if (_Contrat.InternalIsNew)
                throw new InvalidOperationException("_Contrat has never been saved.");

            {
                System.Guid id=_Contrat.GetId().Value;
                if (Data.Contrat_Id!=id)
                    Data.Contrat_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="LieuDeService" /> has been saved for the first time.</summary>
        private void _LieuDeService_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateLieuDeService();
            IsModified=true;
            ((LieuDeService)sender).Saved-=_LieuDeService_Saved;
        }

        /// <summary>Method called when a <see cref="Contrat" /> has been saved for the first time.</summary>
        private void _Contrat_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateContrat();
            IsModified=true;
            ((Contrat)sender).Saved-=_Contrat_Saved;
        }

        /// <summary />
        internal LieuxDeServiceContrats.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary>Returns the <see cref="LieuxDeServiceContrats" /> association instances that are related to the specified entity.</summary>
        public static DomainEntityKeyedCollection<LieuxDeServiceContrats> FindByContrat(Contrat entity, DataMapperCollection dataMappers)
        {
            return ((ILieuxDeServiceContratsMapper)dataMappers[typeof(LieuxDeServiceContrats)]).FindByContrat(entity, dataMappers);
        }

        /// <summary>Returns the <see cref="LieuxDeServiceContrats" /> association instances that are related to the specified entity.</summary>
        public static DomainEntityKeyedCollection<LieuxDeServiceContrats> FindByLieuDeService(LieuDeService entity, DataMapperCollection dataMappers)
        {
            return ((ILieuxDeServiceContratsMapper)dataMappers[typeof(LieuxDeServiceContrats)]).FindByLieuDeService(entity, dataMappers);
        }

        public LieuDeService LieuDeService
        {
            get
            {
                return _LieuDeService;
            }
            private set
            {
                if (_LieuDeService!=value)
                {
                    // If _LieuDeService is new, it has been registered for update when being saved for the first time
                    if ((_LieuDeService!=null) && (_LieuDeService.InternalIsNew))
                        _LieuDeService.Saved-=_LieuDeService_Saved;

                    _LieuDeService=value;

                    // If _LieuDeService is new, its primary key will only be set after being saved for the first time
                    if ((_LieuDeService!=null) && _LieuDeService.InternalIsNew)
                        _LieuDeService.Saved+=_LieuDeService_Saved;
                    else
                        _UpdateLieuDeService();
                }
            }
        }

        public Contrat Contrat
        {
            get
            {
                return _Contrat;
            }
            private set
            {
                if (_Contrat!=value)
                {
                    // If _Contrat is new, it has been registered for update when being saved for the first time
                    if ((_Contrat!=null) && (_Contrat.InternalIsNew))
                        _Contrat.Saved-=_Contrat_Saved;

                    _Contrat=value;

                    // If _Contrat is new, its primary key will only be set after being saved for the first time
                    if ((_Contrat!=null) && _Contrat.InternalIsNew)
                        _Contrat.Saved+=_Contrat_Saved;
                    else
                        _UpdateContrat();
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private LieuDeService _LieuDeService;
        /// <summary />
        private Contrat _Contrat;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Contrat:
        DomainEntity<Contrat.PrimaryKey, Contrat.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Contrat" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Contrat" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Contrat.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Contrat.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String TypeContrat;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Nom;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Domaine;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Boolean Actif;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Contrat():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Contrat" /> entity.</summary>
        public Contrat(DataMapperCollection dataMappers):
            base(dataMappers)
        {
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Contrat" /> entity with serialized data.</summary>
        protected Contrat(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadLieuxDeService(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _LieuxDeService=null;
            _LieuxDeServiceAssociation=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);

            _LoadLieuxDeService(true);
            _LieuxDeServiceAssociation.Delete(e.Context);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_LieuxDeService!=null)
                _LieuxDeService.Save(e.Context);
        }

        /// <summary />
        protected override Contrat.PrimaryKey CreateId()
        {
            return new Contrat.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Contrat.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadLieuxDeService(bool lazyload)
        {
            if (_LieuxDeService==null)
            {
                if (IsNew)
                {
                    _LieuxDeService=new DomainEntityKeyedCollection<LieuDeService>();
                    _LieuxDeServiceAssociation=new DomainEntityKeyedCollection<LieuxDeServiceContrats>();
                } else
                {
                    _LieuxDeService=(DomainEntityKeyedCollection<LieuDeService>)LieuDeService.FindByContrats(this, DataMappers);
                    _LieuxDeServiceAssociation=(DomainEntityKeyedCollection<LieuxDeServiceContrats>)LieuxDeServiceContrats.FindByContrat(this, DataMappers);
                }

                _LieuxDeService.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        if (!((LieuDeService)e.Element).Contrats.Contains(this))
                            ((LieuDeService)e.Element).Contrats.Add(this);
                        break;
                    case CollectionChangeAction.Remove:
                        if (((LieuDeService)e.Element).Contrats.Contains(this))
                            ((LieuDeService)e.Element).Contrats.Remove(this);
                        break;
                    }
                };

                _LieuxDeService.Saving+=delegate(object s, DomainEntityCollectionSavingEventArgs<LieuDeService> e) {
                    foreach (LieuDeService a in e.AddedItems)
                        if (!IsNew && !a.InternalIsNew)
                        {
                            LieuxDeServiceContrats.PrimaryKey pk=new LieuxDeServiceContrats.PrimaryKey(GetId(), a.GetId());
                            try
                            {
                                GC.KeepAlive(_LieuxDeServiceAssociation[pk]);
                            } catch (KeyNotFoundException)
                            {
                                LieuxDeServiceContrats n=new LieuxDeServiceContrats(this, a, DataMappers);
                                _LieuxDeServiceAssociation.Add(n);
                                a.ContratsAssociation.Add(n);
                            }
                        }
                    foreach (LieuDeService r in e.RemovedItems)
                        _LieuxDeServiceAssociation[new LieuxDeServiceContrats.PrimaryKey(Id, r.GetId())].Delete(e.Context);
                };
                _LieuxDeService.Saved+=delegate(object s, PersistenceEventArgs e) {
                    _LieuxDeServiceAssociation.Save(e.Context);
                };
                _LieuxDeServiceAssociation.Deleted+=delegate(object s, PersistenceEventArgs e) {
                    _LieuxDeServiceAssociation.Clear();
                };
            }
        }

        /// <summary>Returns the <see cref="Contrat" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Contrat Find(Contrat.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IContratMapper)dataMappers[typeof(Contrat)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Contrat" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Contrat> FindAll(DataMapperCollection dataMappers)
        {
            return ((IContratMapper)dataMappers[typeof(Contrat)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Contrat" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Contrat> FindByLieuxDeService(LieuDeService entity, DataMapperCollection dataMappers)
        {
            return ((IContratMapper)dataMappers[typeof(Contrat)]).FindByLieuxDeService(entity, dataMappers);
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<LieuDeService> LieuxDeService
        {
            get
            {
                _LoadLieuxDeService(true);
                return new Collection<LieuDeService>(_LieuxDeService);
            }
        }
        /// <summary />
        internal DomainEntityKeyedCollection<LieuxDeServiceContrats> LieuxDeServiceAssociation
        {
            get
            {
                _LoadLieuxDeService(true);
                return _LieuxDeServiceAssociation;
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String TypeContrat
        {
            get
            {
                Load(true);
                return Data.TypeContrat;
            }
            set
            {
                if (Data.TypeContrat!=value)
                {
                    Data.TypeContrat=value;
                    RaisePropertyChanged("TypeContrat");
                }
            }
        }

        /// <summary />
        [StringLengthRule(63)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Nom
        {
            get
            {
                Load(true);
                return Data.Nom;
            }
            set
            {
                if (Data.Nom!=value)
                {
                    Data.Nom=value;
                    RaisePropertyChanged("Nom");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Domaine
        {
            get
            {
                Load(true);
                return Data.Domaine;
            }
            set
            {
                if (Data.Domaine!=value)
                {
                    Data.Domaine=value;
                    RaisePropertyChanged("Domaine");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.Boolean Actif
        {
            get
            {
                Load(true);
                return Data.Actif;
            }
            set
            {
                if (Data.Actif!=value)
                {
                    Data.Actif=value;
                    RaisePropertyChanged("Actif");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private DomainEntityKeyedCollection<LieuDeService> _LieuxDeService;
        /// <summary />
        private DomainEntityKeyedCollection<LieuxDeServiceContrats> _LieuxDeServiceAssociation;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Convention:
        DomainEntity<Convention.PrimaryKey, Convention.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Convention" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Convention" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.String>
        {

            /// <summary>Creates a new instance of the <see cref="Convention.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Convention.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.String numero):
                base(numero)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.String key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.String(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid LieuDeService_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Gestionnaire_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Statut;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Numero;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DateSignature;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Int32? Montant;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Int32? Remise;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Actif;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Convention():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Convention" /> entity.</summary>
        public Convention(LieuDeService lieudeservice, Personne gestionnaire, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            LieuDeService=lieudeservice;
            Gestionnaire=gestionnaire;
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Convention" /> entity with serialized data.</summary>
        protected Convention(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadLieuDeService(lazyLoad);
                _LoadGestionnaire(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _LieuDeService=null;
            _Gestionnaire=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (LieuDeService!=null)
                LieuDeService.Save(e.Context);

            if (Gestionnaire!=null)
                Gestionnaire.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_LieuDeService!=null)
                _LieuDeService.Save(e.Context);
        }

        /// <summary />
        protected override Convention.PrimaryKey CreateId()
        {
            return new Convention.PrimaryKey(Data.Numero);
        }

        /// <summary />
        internal Convention.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.String numero)
        {
            Data.Numero=numero;
        }

        /// <summary />
        private void _LoadLieuDeService(bool lazyload)
        {
            if (_LieuDeService==null)
            {
                if (IsNew)
                    return;

                _LieuDeService=((ILieuDeServiceMapper)DataMappers[typeof(LieuDeService)]).Find(Data.LieuDeService_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="LieuDeService" /> internal information.</summary>
        private void _UpdateLieuDeService()
        {
            Debug.Assert(!_LieuDeService.InternalIsNew);
            if (_LieuDeService.InternalIsNew)
                throw new InvalidOperationException("_LieuDeService has never been saved.");

            {
                System.Guid id=_LieuDeService.GetId().Value;
                if (Data.LieuDeService_Id!=id)
                    Data.LieuDeService_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="LieuDeService" /> has been saved for the first time.</summary>
        private void _LieuDeService_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateLieuDeService();
            IsModified=true;
            ((LieuDeService)sender).Saved-=_LieuDeService_Saved;
        }

        /// <summary />
        private void _LoadGestionnaire(bool lazyload)
        {
            if (_Gestionnaire==null)
            {
                if (IsNew)
                    return;

                _Gestionnaire=((IPersonneMapper)DataMappers[typeof(Personne)]).Find(Data.Gestionnaire_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Gestionnaire" /> internal information.</summary>
        private void _UpdateGestionnaire()
        {
            Debug.Assert(!_Gestionnaire.InternalIsNew);
            if (_Gestionnaire.InternalIsNew)
                throw new InvalidOperationException("_Gestionnaire has never been saved.");

            {
                System.Guid id=_Gestionnaire.GetId().Value;
                if (Data.Gestionnaire_Id!=id)
                    Data.Gestionnaire_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Gestionnaire" /> has been saved for the first time.</summary>
        private void _Gestionnaire_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateGestionnaire();
            IsModified=true;
            ((Personne)sender).Saved-=_Gestionnaire_Saved;
        }

        /// <summary>Returns the <see cref="Convention" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Convention Find(Convention.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IConventionMapper)dataMappers[typeof(Convention)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Convention" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Convention> FindAll(DataMapperCollection dataMappers)
        {
            return ((IConventionMapper)dataMappers[typeof(Convention)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Convention" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Convention> FindByLieuDeService(LieuDeService entity, DataMapperCollection dataMappers)
        {
            return ((IConventionMapper)dataMappers[typeof(Convention)]).FindByLieuDeService(entity, dataMappers);
        }

        /// <summary>Returns the <see cref="Convention" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Convention> FindByGestionnaire(Personne entity, DataMapperCollection dataMappers)
        {
            return ((IConventionMapper)dataMappers[typeof(Convention)]).FindByGestionnaire(entity, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public LieuDeService LieuDeService
        {
            get
            {
                Load(true);
                return _LieuDeService;
            }
            set
            {
                _LoadLieuDeService(true);
                if (_LieuDeService!=value)
                {
                    // If _LieuDeService is new, it has been registered for update when being saved for the first time
                    if ((_LieuDeService!=null) && (_LieuDeService.InternalIsNew))
                        _LieuDeService.Saved-=_LieuDeService_Saved;

                    if (_LieuDeService!=null)
                    {
                        if (_LieuDeService.Conventions.Contains(this))
                            _LieuDeService.Conventions.Remove(this);
                        
                    }
                    if (!value.Conventions.Contains(this))
                        value.Conventions.Add(this);
                    _LieuDeService=value;

                    // If _LieuDeService is new, its primary key will only be set after being saved for the first time
                    if ((_LieuDeService!=null) && _LieuDeService.InternalIsNew)
                        _LieuDeService.Saved+=_LieuDeService_Saved;
                    else
                        _UpdateLieuDeService();

                    RaisePropertyChanged("LieuDeService");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Personne Gestionnaire
        {
            get
            {
                Load(true);
                return _Gestionnaire;
            }
            set
            {
                _LoadGestionnaire(true);
                if (_Gestionnaire!=value)
                {
                    // If _Gestionnaire is new, it has been registered for update when being saved for the first time
                    if ((_Gestionnaire!=null) && (_Gestionnaire.InternalIsNew))
                        _Gestionnaire.Saved-=_Gestionnaire_Saved;

                    if (_Gestionnaire!=null)
                    {
                        if (_Gestionnaire.Conventions.Contains(this))
                            _Gestionnaire.Conventions.Remove(this);
                        
                    }
                    if (!value.Conventions.Contains(this))
                        value.Conventions.Add(this);
                    _Gestionnaire=value;

                    // If _Gestionnaire is new, its primary key will only be set after being saved for the first time
                    if ((_Gestionnaire!=null) && _Gestionnaire.InternalIsNew)
                        _Gestionnaire.Saved+=_Gestionnaire_Saved;
                    else
                        _UpdateGestionnaire();

                    RaisePropertyChanged("Gestionnaire");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Statut
        {
            get
            {
                Load(true);
                return Data.Statut;
            }
            set
            {
                if (Data.Statut!=value)
                {
                    Data.Statut=value;
                    RaisePropertyChanged("Statut");
                }
            }
        }

        /// <summary />
        [NotNullRule]
        [StringLengthRule(8)]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Numero
        {
            get
            {
                Load(true);
                return Data.Numero;
            }
            set
            {
                if (Data.Numero!=value)
                {
                    Data.Numero=value;
                    RaisePropertyChanged("Numero");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DateSignature
        {
            get
            {
                Load(true);
                return Data.DateSignature;
            }
            set
            {
                if (Data.DateSignature!=value)
                {
                    Data.DateSignature=value;
                    RaisePropertyChanged("DateSignature");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.Int32? Montant
        {
            get
            {
                Load(true);
                return Data.Montant;
            }
            set
            {
                if (Data.Montant!=value)
                {
                    Data.Montant=value;
                    RaisePropertyChanged("Montant");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.Int32? Remise
        {
            get
            {
                Load(true);
                return Data.Remise;
            }
            set
            {
                if (Data.Remise!=value)
                {
                    Data.Remise=value;
                    RaisePropertyChanged("Remise");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Actif
        {
            get
            {
                Load(true);
                return Data.Actif;
            }
            set
            {
                if (Data.Actif!=value)
                {
                    Data.Actif=value;
                    RaisePropertyChanged("Actif");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private LieuDeService _LieuDeService;

        /// <summary />
        private Personne _Gestionnaire;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Personne:
        DomainEntity<Personne.PrimaryKey, Personne.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Personne" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Personne" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Personne.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Personne.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid? Adresse_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Nom;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Titre;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String TphFixe;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String TphPortable;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String TphBureau;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Fax;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Fax2;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Mail;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Boolean Actif;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Personne():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Personne" /> entity.</summary>
        public Personne(DataMapperCollection dataMappers):
            base(dataMappers)
        {
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Personne" /> entity with serialized data.</summary>
        protected Personne(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadAdresse(lazyLoad);
                _LoadBranchements(lazyLoad);
                _LoadConventions(lazyLoad);
                _LoadLieuxDeService(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Adresse=null;
            _Branchements=null;
            _Conventions=null;
            _LieuxDeService=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (Adresse!=null)
                Adresse.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);
        }

        /// <summary />
        protected override Personne.PrimaryKey CreateId()
        {
            return new Personne.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Personne.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadAdresse(bool lazyload)
        {
            if (_Adresse==null)
            {
                if (IsNew)
                    return;

                if (!Data.Adresse_Id.HasValue)
                    return;

                _Adresse=((IAdresseMapper)DataMappers[typeof(Adresse)]).Find(Data.Adresse_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Adresse" /> internal information.</summary>
        private void _UpdateAdresse()
        {
            Debug.Assert(!_Adresse.InternalIsNew);
            if (_Adresse.InternalIsNew)
                throw new InvalidOperationException("_Adresse has never been saved.");

            {
                System.Guid? id=(_Adresse!=null ? _Adresse.GetId().Value : (System.Guid?)null);
                if (Data.Adresse_Id!=id)
                    Data.Adresse_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Adresse" /> has been saved for the first time.</summary>
        private void _Adresse_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateAdresse();
            IsModified=true;
            ((Adresse)sender).Saved-=_Adresse_Saved;
        }

        /// <summary />
        private void _LoadBranchements(bool lazyload)
        {
            if (_Branchements==null)
            {
                if (IsNew)
                    _Branchements=new DomainEntityKeyedCollection<Branchement>();
                else
                    _Branchements=(DomainEntityKeyedCollection<Branchement>)Branchement.FindByPersonne(this, DataMappers);

                _Branchements.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Branchement)e.Element).Personne=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Branchement)e.Element).Personne==this)
                            ((Branchement)e.Element).Personne=null;
                        break;
                    }
                };
            }
        }

        /// <summary />
        private void _LoadConventions(bool lazyload)
        {
            if (_Conventions==null)
            {
                if (IsNew)
                    _Conventions=new DomainEntityKeyedCollection<Convention>();
                else
                    _Conventions=(DomainEntityKeyedCollection<Convention>)Convention.FindByGestionnaire(this, DataMappers);

                _Conventions.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Convention)e.Element).Gestionnaire=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Convention)e.Element).Gestionnaire==this)
                            ((Convention)e.Element).Gestionnaire=null;
                        break;
                    }
                };
            }
        }

        /// <summary />
        private void _LoadLieuxDeService(bool lazyload)
        {
            if (_LieuxDeService==null)
            {
                if (IsNew)
                    _LieuxDeService=new DomainEntityKeyedCollection<LieuDeService>();
                else
                    _LieuxDeService=(DomainEntityKeyedCollection<LieuDeService>)LieuDeService.FindByClient(this, DataMappers);

                _LieuxDeService.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((LieuDeService)e.Element).Client=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((LieuDeService)e.Element).Client==this)
                            ((LieuDeService)e.Element).Client=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="Personne" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Personne Find(Personne.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IPersonneMapper)dataMappers[typeof(Personne)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Personne" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Personne> FindAll(DataMapperCollection dataMappers)
        {
            return ((IPersonneMapper)dataMappers[typeof(Personne)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Personne" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Personne> FindByAdresse(Adresse entity, DataMapperCollection dataMappers)
        {
            return ((IPersonneMapper)dataMappers[typeof(Personne)]).FindByAdresse(entity, dataMappers);
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public Adresse Adresse
        {
            get
            {
                Load(true);
                return _Adresse;
            }
            set
            {
                _LoadAdresse(true);
                if (_Adresse!=value)
                {
                    // If _Adresse is new, it has been registered for update when being saved for the first time
                    if ((_Adresse!=null) && (_Adresse.InternalIsNew))
                        _Adresse.Saved-=_Adresse_Saved;

                    if (_Adresse!=null)
                    {
                        if (_Adresse.Personnes.Contains(this))
                            _Adresse.Personnes.Remove(this);
                        
                    }
                    if (!value.Personnes.Contains(this))
                        value.Personnes.Add(this);
                    _Adresse=value;

                    // If _Adresse is new, its primary key will only be set after being saved for the first time
                    if ((_Adresse!=null) && _Adresse.InternalIsNew)
                        _Adresse.Saved+=_Adresse_Saved;
                    else
                        _UpdateAdresse();

                    RaisePropertyChanged("Adresse");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Branchement> Branchements
        {
            get
            {
                _LoadBranchements(true);
                return new Collection<Branchement>(_Branchements);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Convention> Conventions
        {
            get
            {
                _LoadConventions(true);
                return new Collection<Convention>(_Conventions);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<LieuDeService> LieuxDeService
        {
            get
            {
                _LoadLieuxDeService(true);
                return new Collection<LieuDeService>(_LieuxDeService);
            }
        }

        /// <summary />
        [NotNullRule]
        [StringLengthRule(63)]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Nom
        {
            get
            {
                Load(true);
                return Data.Nom;
            }
            set
            {
                if (Data.Nom!=value)
                {
                    Data.Nom=value;
                    RaisePropertyChanged("Nom");
                }
            }
        }

        /// <summary />
        [StringLengthRule(20)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Titre
        {
            get
            {
                Load(true);
                return Data.Titre;
            }
            set
            {
                if (Data.Titre!=value)
                {
                    Data.Titre=value;
                    RaisePropertyChanged("Titre");
                }
            }
        }

        /// <summary />
        [StringLengthRule(25)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String TphFixe
        {
            get
            {
                Load(true);
                return Data.TphFixe;
            }
            set
            {
                if (Data.TphFixe!=value)
                {
                    Data.TphFixe=value;
                    RaisePropertyChanged("TphFixe");
                }
            }
        }

        /// <summary />
        [StringLengthRule(25)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String TphPortable
        {
            get
            {
                Load(true);
                return Data.TphPortable;
            }
            set
            {
                if (Data.TphPortable!=value)
                {
                    Data.TphPortable=value;
                    RaisePropertyChanged("TphPortable");
                }
            }
        }

        /// <summary />
        [StringLengthRule(25)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String TphBureau
        {
            get
            {
                Load(true);
                return Data.TphBureau;
            }
            set
            {
                if (Data.TphBureau!=value)
                {
                    Data.TphBureau=value;
                    RaisePropertyChanged("TphBureau");
                }
            }
        }

        /// <summary />
        [StringLengthRule(25)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Fax
        {
            get
            {
                Load(true);
                return Data.Fax;
            }
            set
            {
                if (Data.Fax!=value)
                {
                    Data.Fax=value;
                    RaisePropertyChanged("Fax");
                }
            }
        }

        /// <summary />
        [StringLengthRule(25)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Fax2
        {
            get
            {
                Load(true);
                return Data.Fax2;
            }
            set
            {
                if (Data.Fax2!=value)
                {
                    Data.Fax2=value;
                    RaisePropertyChanged("Fax2");
                }
            }
        }

        /// <summary />
        [StringLengthRule(127)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Mail
        {
            get
            {
                Load(true);
                return Data.Mail;
            }
            set
            {
                if (Data.Mail!=value)
                {
                    Data.Mail=value;
                    RaisePropertyChanged("Mail");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.Boolean Actif
        {
            get
            {
                Load(true);
                return Data.Actif;
            }
            set
            {
                if (Data.Actif!=value)
                {
                    Data.Actif=value;
                    RaisePropertyChanged("Actif");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private Adresse _Adresse;

        /// <summary />
        private DomainEntityKeyedCollection<Branchement> _Branchements;

        /// <summary />
        private DomainEntityKeyedCollection<Convention> _Conventions;

        /// <summary />
        private DomainEntityKeyedCollection<LieuDeService> _LieuxDeService;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Compteur:
        DomainEntity<Compteur.PrimaryKey, Compteur.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Compteur" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Compteur" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Compteur.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Compteur.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid LieuDeService_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Branchement_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid? Adresse_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String CodeGn;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Numero;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Diametre;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Marque;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Modele;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Localisation;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Boolean Actif;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Compteur():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Compteur" /> entity.</summary>
        public Compteur(LieuDeService lieudeservice, Branchement branchement, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            LieuDeService=lieudeservice;
            Branchement=branchement;
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Compteur" /> entity with serialized data.</summary>
        protected Compteur(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadLieuDeService(lazyLoad);
                _LoadBranchement(lazyLoad);
                _LoadAdresse(lazyLoad);
                _LoadVolumes(lazyLoad);
                _LoadEquipements(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _LieuDeService=null;
            _Branchement=null;
            _Adresse=null;
            _Volumes=null;
            _Equipements=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);

            _LoadVolumes(true);
            _Volumes.Delete(e.Context);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (LieuDeService!=null)
                LieuDeService.Save(e.Context);

            if (Branchement!=null)
                Branchement.Save(e.Context);

            if (Adresse!=null)
                Adresse.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_LieuDeService!=null)
                _LieuDeService.Save(e.Context);

            if (_Branchement!=null)
                _Branchement.Save(e.Context);

            if (_Volumes!=null)
                _Volumes.Save(e.Context);

            if (_Equipements!=null)
                _Equipements.Save(e.Context);
        }

        /// <summary />
        protected override Compteur.PrimaryKey CreateId()
        {
            return new Compteur.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Compteur.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadLieuDeService(bool lazyload)
        {
            if (_LieuDeService==null)
            {
                if (IsNew)
                    return;

                _LieuDeService=((ILieuDeServiceMapper)DataMappers[typeof(LieuDeService)]).Find(Data.LieuDeService_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="LieuDeService" /> internal information.</summary>
        private void _UpdateLieuDeService()
        {
            Debug.Assert(!_LieuDeService.InternalIsNew);
            if (_LieuDeService.InternalIsNew)
                throw new InvalidOperationException("_LieuDeService has never been saved.");

            {
                System.Guid id=_LieuDeService.GetId().Value;
                if (Data.LieuDeService_Id!=id)
                    Data.LieuDeService_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="LieuDeService" /> has been saved for the first time.</summary>
        private void _LieuDeService_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateLieuDeService();
            IsModified=true;
            ((LieuDeService)sender).Saved-=_LieuDeService_Saved;
        }

        /// <summary />
        private void _LoadBranchement(bool lazyload)
        {
            if (_Branchement==null)
            {
                if (IsNew)
                    return;

                _Branchement=((IBranchementMapper)DataMappers[typeof(Branchement)]).Find(Data.Branchement_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Branchement" /> internal information.</summary>
        private void _UpdateBranchement()
        {
            Debug.Assert(!_Branchement.InternalIsNew);
            if (_Branchement.InternalIsNew)
                throw new InvalidOperationException("_Branchement has never been saved.");

            {
                System.Guid id=_Branchement.GetId().Value;
                if (Data.Branchement_Id!=id)
                    Data.Branchement_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Branchement" /> has been saved for the first time.</summary>
        private void _Branchement_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateBranchement();
            IsModified=true;
            ((Branchement)sender).Saved-=_Branchement_Saved;
        }

        /// <summary />
        private void _LoadAdresse(bool lazyload)
        {
            if (_Adresse==null)
            {
                if (IsNew)
                    return;

                if (!Data.Adresse_Id.HasValue)
                    return;

                _Adresse=((IAdresseMapper)DataMappers[typeof(Adresse)]).Find(Data.Adresse_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Adresse" /> internal information.</summary>
        private void _UpdateAdresse()
        {
            Debug.Assert(!_Adresse.InternalIsNew);
            if (_Adresse.InternalIsNew)
                throw new InvalidOperationException("_Adresse has never been saved.");

            {
                System.Guid? id=(_Adresse!=null ? _Adresse.GetId().Value : (System.Guid?)null);
                if (Data.Adresse_Id!=id)
                    Data.Adresse_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Adresse" /> has been saved for the first time.</summary>
        private void _Adresse_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateAdresse();
            IsModified=true;
            ((Adresse)sender).Saved-=_Adresse_Saved;
        }

        /// <summary />
        private void _LoadVolumes(bool lazyload)
        {
            if (_Volumes==null)
            {
                if (IsNew)
                    _Volumes=new DomainEntityKeyedCollection<Volume>();
                else
                    _Volumes=(DomainEntityKeyedCollection<Volume>)Volume.FindByCompteur(this, DataMappers);

                _Volumes.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Volume)e.Element).Compteur=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Volume)e.Element).Compteur==this)
                            ((Volume)e.Element).Compteur=null;
                        break;
                    }
                };
            }
        }

        /// <summary />
        private void _LoadEquipements(bool lazyload)
        {
            if (_Equipements==null)
            {
                if (IsNew)
                    _Equipements=new DomainEntityKeyedCollection<Equipement>();
                else
                    _Equipements=(DomainEntityKeyedCollection<Equipement>)Equipement.FindByCompteur(this, DataMappers);

                _Equipements.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Equipement)e.Element).Compteur=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Equipement)e.Element).Compteur==this)
                            ((Equipement)e.Element).Compteur=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="Compteur" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Compteur Find(Compteur.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((ICompteurMapper)dataMappers[typeof(Compteur)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Compteur" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Compteur> FindAll(DataMapperCollection dataMappers)
        {
            return ((ICompteurMapper)dataMappers[typeof(Compteur)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Compteur" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Compteur> FindByLieuDeService(LieuDeService entity, DataMapperCollection dataMappers)
        {
            return ((ICompteurMapper)dataMappers[typeof(Compteur)]).FindByLieuDeService(entity, dataMappers);
        }

        /// <summary>Returns the <see cref="Compteur" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Compteur> FindByBranchement(Branchement entity, DataMapperCollection dataMappers)
        {
            return ((ICompteurMapper)dataMappers[typeof(Compteur)]).FindByBranchement(entity, dataMappers);
        }

        /// <summary>Returns the <see cref="Compteur" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Compteur> FindByAdresse(Adresse entity, DataMapperCollection dataMappers)
        {
            return ((ICompteurMapper)dataMappers[typeof(Compteur)]).FindByAdresse(entity, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public LieuDeService LieuDeService
        {
            get
            {
                Load(true);
                return _LieuDeService;
            }
            set
            {
                _LoadLieuDeService(true);
                if (_LieuDeService!=value)
                {
                    // If _LieuDeService is new, it has been registered for update when being saved for the first time
                    if ((_LieuDeService!=null) && (_LieuDeService.InternalIsNew))
                        _LieuDeService.Saved-=_LieuDeService_Saved;

                    if (_LieuDeService!=null)
                    {
                        if (_LieuDeService.Compteurs.Contains(this))
                            _LieuDeService.Compteurs.Remove(this);
                        
                    }
                    if (!value.Compteurs.Contains(this))
                        value.Compteurs.Add(this);
                    _LieuDeService=value;

                    // If _LieuDeService is new, its primary key will only be set after being saved for the first time
                    if ((_LieuDeService!=null) && _LieuDeService.InternalIsNew)
                        _LieuDeService.Saved+=_LieuDeService_Saved;
                    else
                        _UpdateLieuDeService();

                    RaisePropertyChanged("LieuDeService");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Branchement Branchement
        {
            get
            {
                Load(true);
                return _Branchement;
            }
            set
            {
                _LoadBranchement(true);
                if (_Branchement!=value)
                {
                    // If _Branchement is new, it has been registered for update when being saved for the first time
                    if ((_Branchement!=null) && (_Branchement.InternalIsNew))
                        _Branchement.Saved-=_Branchement_Saved;

                    if (_Branchement!=null)
                    {
                        if (_Branchement.Compteurs.Contains(this))
                            _Branchement.Compteurs.Remove(this);
                        
                    }
                    if (!value.Compteurs.Contains(this))
                        value.Compteurs.Add(this);
                    _Branchement=value;

                    // If _Branchement is new, its primary key will only be set after being saved for the first time
                    if ((_Branchement!=null) && _Branchement.InternalIsNew)
                        _Branchement.Saved+=_Branchement_Saved;
                    else
                        _UpdateBranchement();

                    RaisePropertyChanged("Branchement");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public Adresse Adresse
        {
            get
            {
                Load(true);
                return _Adresse;
            }
            set
            {
                _LoadAdresse(true);
                if (_Adresse!=value)
                {
                    // If _Adresse is new, it has been registered for update when being saved for the first time
                    if ((_Adresse!=null) && (_Adresse.InternalIsNew))
                        _Adresse.Saved-=_Adresse_Saved;

                    if (_Adresse!=null)
                    {
                        if (_Adresse.Compteurs.Contains(this))
                            _Adresse.Compteurs.Remove(this);
                        
                    }
                    if (!value.Compteurs.Contains(this))
                        value.Compteurs.Add(this);
                    _Adresse=value;

                    // If _Adresse is new, its primary key will only be set after being saved for the first time
                    if ((_Adresse!=null) && _Adresse.InternalIsNew)
                        _Adresse.Saved+=_Adresse_Saved;
                    else
                        _UpdateAdresse();

                    RaisePropertyChanged("Adresse");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Volume> Volumes
        {
            get
            {
                _LoadVolumes(true);
                return new Collection<Volume>(_Volumes);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Equipement> Equipements
        {
            get
            {
                _LoadEquipements(true);
                return new Collection<Equipement>(_Equipements);
            }
        }

        /// <summary />
        [StringLengthRule(14)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String CodeGn
        {
            get
            {
                Load(true);
                return Data.CodeGn;
            }
            set
            {
                if (Data.CodeGn!=value)
                {
                    Data.CodeGn=value;
                    RaisePropertyChanged("CodeGn");
                }
            }
        }

        /// <summary />
        [StringLengthRule(15)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Numero
        {
            get
            {
                Load(true);
                return Data.Numero;
            }
            set
            {
                if (Data.Numero!=value)
                {
                    Data.Numero=value;
                    RaisePropertyChanged("Numero");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Diametre
        {
            get
            {
                Load(true);
                return Data.Diametre;
            }
            set
            {
                if (Data.Diametre!=value)
                {
                    Data.Diametre=value;
                    RaisePropertyChanged("Diametre");
                }
            }
        }

        /// <summary />
        [StringLengthRule(31)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Marque
        {
            get
            {
                Load(true);
                return Data.Marque;
            }
            set
            {
                if (Data.Marque!=value)
                {
                    Data.Marque=value;
                    RaisePropertyChanged("Marque");
                }
            }
        }

        /// <summary />
        [StringLengthRule(31)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Modele
        {
            get
            {
                Load(true);
                return Data.Modele;
            }
            set
            {
                if (Data.Modele!=value)
                {
                    Data.Modele=value;
                    RaisePropertyChanged("Modele");
                }
            }
        }

        /// <summary />
        [StringLengthRule(255)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Localisation
        {
            get
            {
                Load(true);
                return Data.Localisation;
            }
            set
            {
                if (Data.Localisation!=value)
                {
                    Data.Localisation=value;
                    RaisePropertyChanged("Localisation");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.Boolean Actif
        {
            get
            {
                Load(true);
                return Data.Actif;
            }
            set
            {
                if (Data.Actif!=value)
                {
                    Data.Actif=value;
                    RaisePropertyChanged("Actif");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private LieuDeService _LieuDeService;

        /// <summary />
        private Branchement _Branchement;

        /// <summary />
        private Adresse _Adresse;

        /// <summary />
        private DomainEntityKeyedCollection<Volume> _Volumes;

        /// <summary />
        private DomainEntityKeyedCollection<Equipement> _Equipements;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Branchement:
        DomainEntity<Branchement.PrimaryKey, Branchement.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Branchement" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Branchement" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Branchement.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Branchement.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid? Personne_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid? Adresse_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String CodeGn;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Materiau;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Diametre;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Emplacement;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Localisation;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Boolean Actif;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Branchement():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Branchement" /> entity.</summary>
        public Branchement(DataMapperCollection dataMappers):
            base(dataMappers)
        {
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Branchement" /> entity with serialized data.</summary>
        protected Branchement(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadPersonne(lazyLoad);
                _LoadAdresse(lazyLoad);
                _LoadCompteurs(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Personne=null;
            _Adresse=null;
            _Compteurs=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (Personne!=null)
                Personne.Save(e.Context);

            if (Adresse!=null)
                Adresse.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Compteurs!=null)
                _Compteurs.Save(e.Context);
        }

        /// <summary />
        protected override Branchement.PrimaryKey CreateId()
        {
            return new Branchement.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Branchement.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadPersonne(bool lazyload)
        {
            if (_Personne==null)
            {
                if (IsNew)
                    return;

                if (!Data.Personne_Id.HasValue)
                    return;

                _Personne=((IPersonneMapper)DataMappers[typeof(Personne)]).Find(Data.Personne_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Personne" /> internal information.</summary>
        private void _UpdatePersonne()
        {
            Debug.Assert(!_Personne.InternalIsNew);
            if (_Personne.InternalIsNew)
                throw new InvalidOperationException("_Personne has never been saved.");

            {
                System.Guid? id=(_Personne!=null ? _Personne.GetId().Value : (System.Guid?)null);
                if (Data.Personne_Id!=id)
                    Data.Personne_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Personne" /> has been saved for the first time.</summary>
        private void _Personne_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdatePersonne();
            IsModified=true;
            ((Personne)sender).Saved-=_Personne_Saved;
        }

        /// <summary />
        private void _LoadAdresse(bool lazyload)
        {
            if (_Adresse==null)
            {
                if (IsNew)
                    return;

                if (!Data.Adresse_Id.HasValue)
                    return;

                _Adresse=((IAdresseMapper)DataMappers[typeof(Adresse)]).Find(Data.Adresse_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Adresse" /> internal information.</summary>
        private void _UpdateAdresse()
        {
            Debug.Assert(!_Adresse.InternalIsNew);
            if (_Adresse.InternalIsNew)
                throw new InvalidOperationException("_Adresse has never been saved.");

            {
                System.Guid? id=(_Adresse!=null ? _Adresse.GetId().Value : (System.Guid?)null);
                if (Data.Adresse_Id!=id)
                    Data.Adresse_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Adresse" /> has been saved for the first time.</summary>
        private void _Adresse_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateAdresse();
            IsModified=true;
            ((Adresse)sender).Saved-=_Adresse_Saved;
        }

        /// <summary />
        private void _LoadCompteurs(bool lazyload)
        {
            if (_Compteurs==null)
            {
                if (IsNew)
                    _Compteurs=new DomainEntityKeyedCollection<Compteur>();
                else
                    _Compteurs=(DomainEntityKeyedCollection<Compteur>)Compteur.FindByBranchement(this, DataMappers);

                _Compteurs.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Compteur)e.Element).Branchement=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Compteur)e.Element).Branchement==this)
                            ((Compteur)e.Element).Branchement=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="Branchement" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Branchement Find(Branchement.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IBranchementMapper)dataMappers[typeof(Branchement)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Branchement" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Branchement> FindAll(DataMapperCollection dataMappers)
        {
            return ((IBranchementMapper)dataMappers[typeof(Branchement)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Branchement" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Branchement> FindByPersonne(Personne entity, DataMapperCollection dataMappers)
        {
            return ((IBranchementMapper)dataMappers[typeof(Branchement)]).FindByPersonne(entity, dataMappers);
        }

        /// <summary>Returns the <see cref="Branchement" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Branchement> FindByAdresse(Adresse entity, DataMapperCollection dataMappers)
        {
            return ((IBranchementMapper)dataMappers[typeof(Branchement)]).FindByAdresse(entity, dataMappers);
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public Personne Personne
        {
            get
            {
                Load(true);
                return _Personne;
            }
            set
            {
                _LoadPersonne(true);
                if (_Personne!=value)
                {
                    // If _Personne is new, it has been registered for update when being saved for the first time
                    if ((_Personne!=null) && (_Personne.InternalIsNew))
                        _Personne.Saved-=_Personne_Saved;

                    if (_Personne!=null)
                    {
                        if (_Personne.Branchements.Contains(this))
                            _Personne.Branchements.Remove(this);
                        
                    }
                    if (!value.Branchements.Contains(this))
                        value.Branchements.Add(this);
                    _Personne=value;

                    // If _Personne is new, its primary key will only be set after being saved for the first time
                    if ((_Personne!=null) && _Personne.InternalIsNew)
                        _Personne.Saved+=_Personne_Saved;
                    else
                        _UpdatePersonne();

                    RaisePropertyChanged("Personne");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public Adresse Adresse
        {
            get
            {
                Load(true);
                return _Adresse;
            }
            set
            {
                _LoadAdresse(true);
                if (_Adresse!=value)
                {
                    // If _Adresse is new, it has been registered for update when being saved for the first time
                    if ((_Adresse!=null) && (_Adresse.InternalIsNew))
                        _Adresse.Saved-=_Adresse_Saved;

                    if (_Adresse!=null)
                    {
                        if (_Adresse.Branchements.Contains(this))
                            _Adresse.Branchements.Remove(this);
                        
                    }
                    if (!value.Branchements.Contains(this))
                        value.Branchements.Add(this);
                    _Adresse=value;

                    // If _Adresse is new, its primary key will only be set after being saved for the first time
                    if ((_Adresse!=null) && _Adresse.InternalIsNew)
                        _Adresse.Saved+=_Adresse_Saved;
                    else
                        _UpdateAdresse();

                    RaisePropertyChanged("Adresse");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Compteur> Compteurs
        {
            get
            {
                _LoadCompteurs(true);
                return new Collection<Compteur>(_Compteurs);
            }
        }

        /// <summary />
        [StringLengthRule(14)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String CodeGn
        {
            get
            {
                Load(true);
                return Data.CodeGn;
            }
            set
            {
                if (Data.CodeGn!=value)
                {
                    Data.CodeGn=value;
                    RaisePropertyChanged("CodeGn");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Materiau
        {
            get
            {
                Load(true);
                return Data.Materiau;
            }
            set
            {
                if (Data.Materiau!=value)
                {
                    Data.Materiau=value;
                    RaisePropertyChanged("Materiau");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Diametre
        {
            get
            {
                Load(true);
                return Data.Diametre;
            }
            set
            {
                if (Data.Diametre!=value)
                {
                    Data.Diametre=value;
                    RaisePropertyChanged("Diametre");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Emplacement
        {
            get
            {
                Load(true);
                return Data.Emplacement;
            }
            set
            {
                if (Data.Emplacement!=value)
                {
                    Data.Emplacement=value;
                    RaisePropertyChanged("Emplacement");
                }
            }
        }

        /// <summary />
        [StringLengthRule(255)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Localisation
        {
            get
            {
                Load(true);
                return Data.Localisation;
            }
            set
            {
                if (Data.Localisation!=value)
                {
                    Data.Localisation=value;
                    RaisePropertyChanged("Localisation");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.Boolean Actif
        {
            get
            {
                Load(true);
                return Data.Actif;
            }
            set
            {
                if (Data.Actif!=value)
                {
                    Data.Actif=value;
                    RaisePropertyChanged("Actif");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private Personne _Personne;

        /// <summary />
        private Adresse _Adresse;

        /// <summary />
        private DomainEntityKeyedCollection<Compteur> _Compteurs;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Volume:
        DomainEntity<Volume.PrimaryKey, Volume.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Volume" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Volume" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Volume.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Volume.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Compteur_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DateValeur;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Int64? Valeur;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Volume():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Volume" /> entity.</summary>
        public Volume(Compteur compteur, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            Compteur=compteur;
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Volume" /> entity with serialized data.</summary>
        protected Volume(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadCompteur(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Compteur=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (Compteur!=null)
                Compteur.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Compteur!=null)
                _Compteur.Save(e.Context);
        }

        /// <summary />
        protected override Volume.PrimaryKey CreateId()
        {
            return new Volume.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Volume.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadCompteur(bool lazyload)
        {
            if (_Compteur==null)
            {
                if (IsNew)
                    return;

                _Compteur=((ICompteurMapper)DataMappers[typeof(Compteur)]).Find(Data.Compteur_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Compteur" /> internal information.</summary>
        private void _UpdateCompteur()
        {
            Debug.Assert(!_Compteur.InternalIsNew);
            if (_Compteur.InternalIsNew)
                throw new InvalidOperationException("_Compteur has never been saved.");

            {
                System.Guid id=_Compteur.GetId().Value;
                if (Data.Compteur_Id!=id)
                    Data.Compteur_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Compteur" /> has been saved for the first time.</summary>
        private void _Compteur_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateCompteur();
            IsModified=true;
            ((Compteur)sender).Saved-=_Compteur_Saved;
        }

        /// <summary>Returns the <see cref="Volume" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Volume Find(Volume.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IVolumeMapper)dataMappers[typeof(Volume)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Volume" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Volume> FindAll(DataMapperCollection dataMappers)
        {
            return ((IVolumeMapper)dataMappers[typeof(Volume)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Volume" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Volume> FindByCompteur(Compteur entity, DataMapperCollection dataMappers)
        {
            return ((IVolumeMapper)dataMappers[typeof(Volume)]).FindByCompteur(entity, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Compteur Compteur
        {
            get
            {
                Load(true);
                return _Compteur;
            }
            set
            {
                _LoadCompteur(true);
                if (_Compteur!=value)
                {
                    // If _Compteur is new, it has been registered for update when being saved for the first time
                    if ((_Compteur!=null) && (_Compteur.InternalIsNew))
                        _Compteur.Saved-=_Compteur_Saved;

                    if (_Compteur!=null)
                    {
                        if (_Compteur.Volumes.Contains(this))
                            _Compteur.Volumes.Remove(this);
                        
                    }
                    if (!value.Volumes.Contains(this))
                        value.Volumes.Add(this);
                    _Compteur=value;

                    // If _Compteur is new, its primary key will only be set after being saved for the first time
                    if ((_Compteur!=null) && _Compteur.InternalIsNew)
                        _Compteur.Saved+=_Compteur_Saved;
                    else
                        _UpdateCompteur();

                    RaisePropertyChanged("Compteur");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DateValeur
        {
            get
            {
                Load(true);
                return Data.DateValeur;
            }
            set
            {
                if (Data.DateValeur!=value)
                {
                    Data.DateValeur=value;
                    RaisePropertyChanged("DateValeur");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.Int64? Valeur
        {
            get
            {
                Load(true);
                return Data.Valeur;
            }
            set
            {
                if (Data.Valeur!=value)
                {
                    Data.Valeur=value;
                    RaisePropertyChanged("Valeur");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private Compteur _Compteur;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Equipement:
        DomainEntity<Equipement.PrimaryKey, Equipement.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Equipement" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Equipement" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Equipement.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Equipement.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Compteur_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String TypeEquipement;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Statut;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Diametre;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Marque;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Modele;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Numero;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Rang;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DatePose;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Localisation;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Boolean? Conventionne;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Boolean Actif;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Equipement():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Equipement" /> entity.</summary>
        public Equipement(Compteur compteur, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            Compteur=compteur;
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Equipement" /> entity with serialized data.</summary>
        protected Equipement(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadCompteur(lazyLoad);
                _LoadInterventions(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Compteur=null;
            _Interventions=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);

            _LoadInterventions(true);
            _Interventions.Delete(e.Context);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (Compteur!=null)
                Compteur.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Compteur!=null)
                _Compteur.Save(e.Context);

            if (_Interventions!=null)
                _Interventions.Save(e.Context);
        }

        /// <summary />
        protected override Equipement.PrimaryKey CreateId()
        {
            return new Equipement.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Equipement.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadCompteur(bool lazyload)
        {
            if (_Compteur==null)
            {
                if (IsNew)
                    return;

                _Compteur=((ICompteurMapper)DataMappers[typeof(Compteur)]).Find(Data.Compteur_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Compteur" /> internal information.</summary>
        private void _UpdateCompteur()
        {
            Debug.Assert(!_Compteur.InternalIsNew);
            if (_Compteur.InternalIsNew)
                throw new InvalidOperationException("_Compteur has never been saved.");

            {
                System.Guid id=_Compteur.GetId().Value;
                if (Data.Compteur_Id!=id)
                    Data.Compteur_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Compteur" /> has been saved for the first time.</summary>
        private void _Compteur_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateCompteur();
            IsModified=true;
            ((Compteur)sender).Saved-=_Compteur_Saved;
        }

        /// <summary />
        private void _LoadInterventions(bool lazyload)
        {
            if (_Interventions==null)
            {
                if (IsNew)
                    _Interventions=new DomainEntityKeyedCollection<Intervention>();
                else
                    _Interventions=(DomainEntityKeyedCollection<Intervention>)Intervention.FindByEquipement(this, DataMappers);

                _Interventions.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Intervention)e.Element).Equipement=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Intervention)e.Element).Equipement==this)
                            ((Intervention)e.Element).Equipement=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="Equipement" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Equipement Find(Equipement.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IEquipementMapper)dataMappers[typeof(Equipement)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Equipement" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Equipement> FindAll(DataMapperCollection dataMappers)
        {
            return ((IEquipementMapper)dataMappers[typeof(Equipement)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Equipement" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Equipement> FindByCompteur(Compteur entity, DataMapperCollection dataMappers)
        {
            return ((IEquipementMapper)dataMappers[typeof(Equipement)]).FindByCompteur(entity, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Compteur Compteur
        {
            get
            {
                Load(true);
                return _Compteur;
            }
            set
            {
                _LoadCompteur(true);
                if (_Compteur!=value)
                {
                    // If _Compteur is new, it has been registered for update when being saved for the first time
                    if ((_Compteur!=null) && (_Compteur.InternalIsNew))
                        _Compteur.Saved-=_Compteur_Saved;

                    if (_Compteur!=null)
                    {
                        if (_Compteur.Equipements.Contains(this))
                            _Compteur.Equipements.Remove(this);
                        
                    }
                    if (!value.Equipements.Contains(this))
                        value.Equipements.Add(this);
                    _Compteur=value;

                    // If _Compteur is new, its primary key will only be set after being saved for the first time
                    if ((_Compteur!=null) && _Compteur.InternalIsNew)
                        _Compteur.Saved+=_Compteur_Saved;
                    else
                        _UpdateCompteur();

                    RaisePropertyChanged("Compteur");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Intervention> Interventions
        {
            get
            {
                _LoadInterventions(true);
                return new Collection<Intervention>(_Interventions);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String TypeEquipement
        {
            get
            {
                Load(true);
                return Data.TypeEquipement;
            }
            set
            {
                if (Data.TypeEquipement!=value)
                {
                    Data.TypeEquipement=value;
                    RaisePropertyChanged("TypeEquipement");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Statut
        {
            get
            {
                Load(true);
                return Data.Statut;
            }
            set
            {
                if (Data.Statut!=value)
                {
                    Data.Statut=value;
                    RaisePropertyChanged("Statut");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Diametre
        {
            get
            {
                Load(true);
                return Data.Diametre;
            }
            set
            {
                if (Data.Diametre!=value)
                {
                    Data.Diametre=value;
                    RaisePropertyChanged("Diametre");
                }
            }
        }

        /// <summary />
        [StringLengthRule(31)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Marque
        {
            get
            {
                Load(true);
                return Data.Marque;
            }
            set
            {
                if (Data.Marque!=value)
                {
                    Data.Marque=value;
                    RaisePropertyChanged("Marque");
                }
            }
        }

        /// <summary />
        [StringLengthRule(31)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Modele
        {
            get
            {
                Load(true);
                return Data.Modele;
            }
            set
            {
                if (Data.Modele!=value)
                {
                    Data.Modele=value;
                    RaisePropertyChanged("Modele");
                }
            }
        }

        /// <summary />
        [StringLengthRule(15)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Numero
        {
            get
            {
                Load(true);
                return Data.Numero;
            }
            set
            {
                if (Data.Numero!=value)
                {
                    Data.Numero=value;
                    RaisePropertyChanged("Numero");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Rang
        {
            get
            {
                Load(true);
                return Data.Rang;
            }
            set
            {
                if (Data.Rang!=value)
                {
                    Data.Rang=value;
                    RaisePropertyChanged("Rang");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DatePose
        {
            get
            {
                Load(true);
                return Data.DatePose;
            }
            set
            {
                if (Data.DatePose!=value)
                {
                    Data.DatePose=value;
                    RaisePropertyChanged("DatePose");
                }
            }
        }

        /// <summary />
        [StringLengthRule(255)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Localisation
        {
            get
            {
                Load(true);
                return Data.Localisation;
            }
            set
            {
                if (Data.Localisation!=value)
                {
                    Data.Localisation=value;
                    RaisePropertyChanged("Localisation");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.Boolean? Conventionne
        {
            get
            {
                Load(true);
                return Data.Conventionne;
            }
            set
            {
                if (Data.Conventionne!=value)
                {
                    Data.Conventionne=value;
                    RaisePropertyChanged("Conventionne");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.Boolean Actif
        {
            get
            {
                Load(true);
                return Data.Actif;
            }
            set
            {
                if (Data.Actif!=value)
                {
                    Data.Actif=value;
                    RaisePropertyChanged("Actif");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private Compteur _Compteur;

        /// <summary />
        private DomainEntityKeyedCollection<Intervention> _Interventions;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Dossier:
        DomainEntity<Dossier.PrimaryKey, Dossier.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Dossier" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Dossier" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Dossier.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Dossier.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid LieuDeService_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid? Programme_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String TypeDossier;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DateOuverture;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? Delai;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DateCloture;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Statut;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Commentaire;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Dossier():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Dossier" /> entity.</summary>
        public Dossier(LieuDeService lieudeservice, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            LieuDeService=lieudeservice;
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Dossier" /> entity with serialized data.</summary>
        protected Dossier(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadLieuDeService(lazyLoad);
                _LoadProgramme(lazyLoad);
                _LoadEtapes(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _LieuDeService=null;
            _Programme=null;
            _Etapes=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);

            _LoadEtapes(true);
            _Etapes.Delete(e.Context);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (LieuDeService!=null)
                LieuDeService.Save(e.Context);

            if (Programme!=null)
                Programme.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_LieuDeService!=null)
                _LieuDeService.Save(e.Context);

            if (_Programme!=null)
                _Programme.Save(e.Context);

            if (_Etapes!=null)
                _Etapes.Save(e.Context);
        }

        /// <summary />
        protected override Dossier.PrimaryKey CreateId()
        {
            return new Dossier.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Dossier.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadLieuDeService(bool lazyload)
        {
            if (_LieuDeService==null)
            {
                if (IsNew)
                    return;

                _LieuDeService=((ILieuDeServiceMapper)DataMappers[typeof(LieuDeService)]).Find(Data.LieuDeService_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="LieuDeService" /> internal information.</summary>
        private void _UpdateLieuDeService()
        {
            Debug.Assert(!_LieuDeService.InternalIsNew);
            if (_LieuDeService.InternalIsNew)
                throw new InvalidOperationException("_LieuDeService has never been saved.");

            {
                System.Guid id=_LieuDeService.GetId().Value;
                if (Data.LieuDeService_Id!=id)
                    Data.LieuDeService_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="LieuDeService" /> has been saved for the first time.</summary>
        private void _LieuDeService_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateLieuDeService();
            IsModified=true;
            ((LieuDeService)sender).Saved-=_LieuDeService_Saved;
        }

        /// <summary />
        private void _LoadProgramme(bool lazyload)
        {
            if (_Programme==null)
            {
                if (IsNew)
                    return;

                if (!Data.Programme_Id.HasValue)
                    return;

                _Programme=((IProgrammeMapper)DataMappers[typeof(Programme)]).Find(Data.Programme_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Programme" /> internal information.</summary>
        private void _UpdateProgramme()
        {
            Debug.Assert(!_Programme.InternalIsNew);
            if (_Programme.InternalIsNew)
                throw new InvalidOperationException("_Programme has never been saved.");

            {
                System.Guid? id=(_Programme!=null ? _Programme.GetId().Value : (System.Guid?)null);
                if (Data.Programme_Id!=id)
                    Data.Programme_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Programme" /> has been saved for the first time.</summary>
        private void _Programme_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateProgramme();
            IsModified=true;
            ((Programme)sender).Saved-=_Programme_Saved;
        }

        /// <summary />
        private void _LoadEtapes(bool lazyload)
        {
            if (_Etapes==null)
            {
                if (IsNew)
                    _Etapes=new DomainEntityKeyedCollection<Etape>();
                else
                    _Etapes=(DomainEntityKeyedCollection<Etape>)Etape.FindByDossier(this, DataMappers);

                _Etapes.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Etape)e.Element).Dossier=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Etape)e.Element).Dossier==this)
                            ((Etape)e.Element).Dossier=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="Dossier" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Dossier Find(Dossier.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IDossierMapper)dataMappers[typeof(Dossier)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Dossier" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Dossier> FindAll(DataMapperCollection dataMappers)
        {
            return ((IDossierMapper)dataMappers[typeof(Dossier)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Dossier" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Dossier> FindByLieuDeService(LieuDeService entity, DataMapperCollection dataMappers)
        {
            return ((IDossierMapper)dataMappers[typeof(Dossier)]).FindByLieuDeService(entity, dataMappers);
        }

        /// <summary>Returns the <see cref="Dossier" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Dossier> FindByProgramme(Programme entity, DataMapperCollection dataMappers)
        {
            return ((IDossierMapper)dataMappers[typeof(Dossier)]).FindByProgramme(entity, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public LieuDeService LieuDeService
        {
            get
            {
                Load(true);
                return _LieuDeService;
            }
            set
            {
                _LoadLieuDeService(true);
                if (_LieuDeService!=value)
                {
                    // If _LieuDeService is new, it has been registered for update when being saved for the first time
                    if ((_LieuDeService!=null) && (_LieuDeService.InternalIsNew))
                        _LieuDeService.Saved-=_LieuDeService_Saved;

                    if (_LieuDeService!=null)
                    {
                        if (_LieuDeService.Dossiers.Contains(this))
                            _LieuDeService.Dossiers.Remove(this);
                        
                    }
                    if (!value.Dossiers.Contains(this))
                        value.Dossiers.Add(this);
                    _LieuDeService=value;

                    // If _LieuDeService is new, its primary key will only be set after being saved for the first time
                    if ((_LieuDeService!=null) && _LieuDeService.InternalIsNew)
                        _LieuDeService.Saved+=_LieuDeService_Saved;
                    else
                        _UpdateLieuDeService();

                    RaisePropertyChanged("LieuDeService");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public Programme Programme
        {
            get
            {
                Load(true);
                return _Programme;
            }
            set
            {
                _LoadProgramme(true);
                if (_Programme!=value)
                {
                    // If _Programme is new, it has been registered for update when being saved for the first time
                    if ((_Programme!=null) && (_Programme.InternalIsNew))
                        _Programme.Saved-=_Programme_Saved;

                    if (_Programme!=null)
                    {
                        if (_Programme.Dossiers.Contains(this))
                            _Programme.Dossiers.Remove(this);
                        
                    }
                    if (!value.Dossiers.Contains(this))
                        value.Dossiers.Add(this);
                    _Programme=value;

                    // If _Programme is new, its primary key will only be set after being saved for the first time
                    if ((_Programme!=null) && _Programme.InternalIsNew)
                        _Programme.Saved+=_Programme_Saved;
                    else
                        _UpdateProgramme();

                    RaisePropertyChanged("Programme");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Etape> Etapes
        {
            get
            {
                _LoadEtapes(true);
                return new Collection<Etape>(_Etapes);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String TypeDossier
        {
            get
            {
                Load(true);
                return Data.TypeDossier;
            }
            set
            {
                if (Data.TypeDossier!=value)
                {
                    Data.TypeDossier=value;
                    RaisePropertyChanged("TypeDossier");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DateOuverture
        {
            get
            {
                Load(true);
                return Data.DateOuverture;
            }
            set
            {
                if (Data.DateOuverture!=value)
                {
                    Data.DateOuverture=value;
                    RaisePropertyChanged("DateOuverture");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? Delai
        {
            get
            {
                Load(true);
                return Data.Delai;
            }
            set
            {
                if (Data.Delai!=value)
                {
                    Data.Delai=value;
                    RaisePropertyChanged("Delai");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DateCloture
        {
            get
            {
                Load(true);
                return Data.DateCloture;
            }
            set
            {
                if (Data.DateCloture!=value)
                {
                    Data.DateCloture=value;
                    RaisePropertyChanged("DateCloture");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Statut
        {
            get
            {
                Load(true);
                return Data.Statut;
            }
            set
            {
                if (Data.Statut!=value)
                {
                    Data.Statut=value;
                    RaisePropertyChanged("Statut");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Commentaire
        {
            get
            {
                Load(true);
                return Data.Commentaire;
            }
            set
            {
                if (Data.Commentaire!=value)
                {
                    Data.Commentaire=value;
                    RaisePropertyChanged("Commentaire");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private LieuDeService _LieuDeService;

        /// <summary />
        private Programme _Programme;

        /// <summary />
        private DomainEntityKeyedCollection<Etape> _Etapes;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Programme:
        DomainEntity<Programme.PrimaryKey, Programme.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Programme" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Programme" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Programme.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Programme.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Nom;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String TypeProgramme;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DateOuverture;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? Delai;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DateCloture;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Statut;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Commentaire;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Programme():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Programme" /> entity.</summary>
        public Programme(DataMapperCollection dataMappers):
            base(dataMappers)
        {
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Programme" /> entity with serialized data.</summary>
        protected Programme(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadDossiers(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Dossiers=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Dossiers!=null)
                _Dossiers.Save(e.Context);
        }

        /// <summary />
        protected override Programme.PrimaryKey CreateId()
        {
            return new Programme.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Programme.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadDossiers(bool lazyload)
        {
            if (_Dossiers==null)
            {
                if (IsNew)
                    _Dossiers=new DomainEntityKeyedCollection<Dossier>();
                else
                    _Dossiers=(DomainEntityKeyedCollection<Dossier>)Dossier.FindByProgramme(this, DataMappers);

                _Dossiers.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Dossier)e.Element).Programme=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Dossier)e.Element).Programme==this)
                            ((Dossier)e.Element).Programme=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="Programme" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Programme Find(Programme.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IProgrammeMapper)dataMappers[typeof(Programme)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Programme" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Programme> FindAll(DataMapperCollection dataMappers)
        {
            return ((IProgrammeMapper)dataMappers[typeof(Programme)]).FindAll(dataMappers);
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Dossier> Dossiers
        {
            get
            {
                _LoadDossiers(true);
                return new Collection<Dossier>(_Dossiers);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Nom
        {
            get
            {
                Load(true);
                return Data.Nom;
            }
            set
            {
                if (Data.Nom!=value)
                {
                    Data.Nom=value;
                    RaisePropertyChanged("Nom");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String TypeProgramme
        {
            get
            {
                Load(true);
                return Data.TypeProgramme;
            }
            set
            {
                if (Data.TypeProgramme!=value)
                {
                    Data.TypeProgramme=value;
                    RaisePropertyChanged("TypeProgramme");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DateOuverture
        {
            get
            {
                Load(true);
                return Data.DateOuverture;
            }
            set
            {
                if (Data.DateOuverture!=value)
                {
                    Data.DateOuverture=value;
                    RaisePropertyChanged("DateOuverture");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? Delai
        {
            get
            {
                Load(true);
                return Data.Delai;
            }
            set
            {
                if (Data.Delai!=value)
                {
                    Data.Delai=value;
                    RaisePropertyChanged("Delai");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DateCloture
        {
            get
            {
                Load(true);
                return Data.DateCloture;
            }
            set
            {
                if (Data.DateCloture!=value)
                {
                    Data.DateCloture=value;
                    RaisePropertyChanged("DateCloture");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Statut
        {
            get
            {
                Load(true);
                return Data.Statut;
            }
            set
            {
                if (Data.Statut!=value)
                {
                    Data.Statut=value;
                    RaisePropertyChanged("Statut");
                }
            }
        }

        /// <summary />
        [StringLengthRule(255)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Commentaire
        {
            get
            {
                Load(true);
                return Data.Commentaire;
            }
            set
            {
                if (Data.Commentaire!=value)
                {
                    Data.Commentaire=value;
                    RaisePropertyChanged("Commentaire");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private DomainEntityKeyedCollection<Dossier> _Dossiers;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Etape:
        DomainEntity<Etape.PrimaryKey, Etape.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Etape" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Etape" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Etape.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Etape.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Dossier_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String TypeEtape;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DatePlanification;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DateOuverture;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? Delai;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DateRealisation;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Statut;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Commentaire;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Etape():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Etape" /> entity.</summary>
        public Etape(Dossier dossier, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            Dossier=dossier;
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Etape" /> entity with serialized data.</summary>
        protected Etape(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadDossier(lazyLoad);
                _LoadActions(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Dossier=null;
            _Actions=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);

            _LoadActions(true);
            _Actions.Delete(e.Context);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (Dossier!=null)
                Dossier.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Dossier!=null)
                _Dossier.Save(e.Context);

            if (_Actions!=null)
                _Actions.Save(e.Context);
        }

        /// <summary />
        protected override Etape.PrimaryKey CreateId()
        {
            return new Etape.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Etape.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadDossier(bool lazyload)
        {
            if (_Dossier==null)
            {
                if (IsNew)
                    return;

                _Dossier=((IDossierMapper)DataMappers[typeof(Dossier)]).Find(Data.Dossier_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Dossier" /> internal information.</summary>
        private void _UpdateDossier()
        {
            Debug.Assert(!_Dossier.InternalIsNew);
            if (_Dossier.InternalIsNew)
                throw new InvalidOperationException("_Dossier has never been saved.");

            {
                System.Guid id=_Dossier.GetId().Value;
                if (Data.Dossier_Id!=id)
                    Data.Dossier_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Dossier" /> has been saved for the first time.</summary>
        private void _Dossier_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateDossier();
            IsModified=true;
            ((Dossier)sender).Saved-=_Dossier_Saved;
        }

        /// <summary />
        private void _LoadActions(bool lazyload)
        {
            if (_Actions==null)
            {
                if (IsNew)
                    _Actions=new DomainEntityKeyedCollection<Action>();
                else
                    _Actions=(DomainEntityKeyedCollection<Action>)Action.FindByEtape(this, DataMappers);

                _Actions.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Action)e.Element).Etape=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Action)e.Element).Etape==this)
                            ((Action)e.Element).Etape=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="Etape" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Etape Find(Etape.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IEtapeMapper)dataMappers[typeof(Etape)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Etape" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Etape> FindAll(DataMapperCollection dataMappers)
        {
            return ((IEtapeMapper)dataMappers[typeof(Etape)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Etape" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Etape> FindByDossier(Dossier entity, DataMapperCollection dataMappers)
        {
            return ((IEtapeMapper)dataMappers[typeof(Etape)]).FindByDossier(entity, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Dossier Dossier
        {
            get
            {
                Load(true);
                return _Dossier;
            }
            set
            {
                _LoadDossier(true);
                if (_Dossier!=value)
                {
                    // If _Dossier is new, it has been registered for update when being saved for the first time
                    if ((_Dossier!=null) && (_Dossier.InternalIsNew))
                        _Dossier.Saved-=_Dossier_Saved;

                    if (_Dossier!=null)
                    {
                        if (_Dossier.Etapes.Contains(this))
                            _Dossier.Etapes.Remove(this);
                        
                    }
                    if (!value.Etapes.Contains(this))
                        value.Etapes.Add(this);
                    _Dossier=value;

                    // If _Dossier is new, its primary key will only be set after being saved for the first time
                    if ((_Dossier!=null) && _Dossier.InternalIsNew)
                        _Dossier.Saved+=_Dossier_Saved;
                    else
                        _UpdateDossier();

                    RaisePropertyChanged("Dossier");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Action> Actions
        {
            get
            {
                _LoadActions(true);
                return new Collection<Action>(_Actions);
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String TypeEtape
        {
            get
            {
                Load(true);
                return Data.TypeEtape;
            }
            set
            {
                if (Data.TypeEtape!=value)
                {
                    Data.TypeEtape=value;
                    RaisePropertyChanged("TypeEtape");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DatePlanification
        {
            get
            {
                Load(true);
                return Data.DatePlanification;
            }
            set
            {
                if (Data.DatePlanification!=value)
                {
                    Data.DatePlanification=value;
                    RaisePropertyChanged("DatePlanification");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DateOuverture
        {
            get
            {
                Load(true);
                return Data.DateOuverture;
            }
            set
            {
                if (Data.DateOuverture!=value)
                {
                    Data.DateOuverture=value;
                    RaisePropertyChanged("DateOuverture");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? Delai
        {
            get
            {
                Load(true);
                return Data.Delai;
            }
            set
            {
                if (Data.Delai!=value)
                {
                    Data.Delai=value;
                    RaisePropertyChanged("Delai");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DateRealisation
        {
            get
            {
                Load(true);
                return Data.DateRealisation;
            }
            set
            {
                if (Data.DateRealisation!=value)
                {
                    Data.DateRealisation=value;
                    RaisePropertyChanged("DateRealisation");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Statut
        {
            get
            {
                Load(true);
                return Data.Statut;
            }
            set
            {
                if (Data.Statut!=value)
                {
                    Data.Statut=value;
                    RaisePropertyChanged("Statut");
                }
            }
        }

        /// <summary />
        [StringLengthRule(255)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Commentaire
        {
            get
            {
                Load(true);
                return Data.Commentaire;
            }
            set
            {
                if (Data.Commentaire!=value)
                {
                    Data.Commentaire=value;
                    RaisePropertyChanged("Commentaire");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private Dossier _Dossier;

        /// <summary />
        private DomainEntityKeyedCollection<Action> _Actions;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Action:
        DomainEntity<Action.PrimaryKey, Action.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Action" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Action" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Action.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Action.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary>Creates a new instance of the <see cref="DataTransfer" /> class.</summary>
           public DataTransfer()
           {
               Type="Action";
           }

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            public string Type;
#endif

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Etape_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String TypeAction;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DatePlanification;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DateOuverture;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Acteur;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? Delai;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.DateTime? DateRealisation;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Statut;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Commentaire;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Action():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Action" /> entity.</summary>
        public Action(Etape etape, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            Etape=etape;
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Action" /> entity with serialized data.</summary>
        protected Action(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadEtape(lazyLoad);
                _LoadDocuments(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Etape=null;
            _Documents=null;
            _DocumentsAssociation=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);

            _LoadDocuments(true);
            _DocumentsAssociation.Delete(e.Context);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (Etape!=null)
                Etape.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Etape!=null)
                _Etape.Save(e.Context);

            if (_Documents!=null)
                _Documents.Save(e.Context);
        }

        /// <summary />
        protected override Action.PrimaryKey CreateId()
        {
            return new Action.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Action.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadEtape(bool lazyload)
        {
            if (_Etape==null)
            {
                if (IsNew)
                    return;

                _Etape=((IEtapeMapper)DataMappers[typeof(Etape)]).Find(Data.Etape_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Etape" /> internal information.</summary>
        private void _UpdateEtape()
        {
            Debug.Assert(!_Etape.InternalIsNew);
            if (_Etape.InternalIsNew)
                throw new InvalidOperationException("_Etape has never been saved.");

            {
                System.Guid id=_Etape.GetId().Value;
                if (Data.Etape_Id!=id)
                    Data.Etape_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Etape" /> has been saved for the first time.</summary>
        private void _Etape_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateEtape();
            IsModified=true;
            ((Etape)sender).Saved-=_Etape_Saved;
        }

        /// <summary />
        private void _LoadDocuments(bool lazyload)
        {
            if (_Documents==null)
            {
                if (IsNew)
                {
                    _Documents=new DomainEntityKeyedCollection<Document>();
                    _DocumentsAssociation=new DomainEntityKeyedCollection<ActionsDocuments>();
                } else
                {
                    _Documents=(DomainEntityKeyedCollection<Document>)Document.FindByActions(this, DataMappers);
                    _DocumentsAssociation=(DomainEntityKeyedCollection<ActionsDocuments>)ActionsDocuments.FindByAction(this, DataMappers);
                }

                _Documents.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        if (!((Document)e.Element).Actions.Contains(this))
                            ((Document)e.Element).Actions.Add(this);
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Document)e.Element).Actions.Contains(this))
                            ((Document)e.Element).Actions.Remove(this);
                        break;
                    }
                };

                _Documents.Saving+=delegate(object s, DomainEntityCollectionSavingEventArgs<Document> e) {
                    foreach (Document a in e.AddedItems)
                        if (!IsNew && !a.InternalIsNew)
                        {
                            ActionsDocuments.PrimaryKey pk=new ActionsDocuments.PrimaryKey(GetId(), a.GetId());
                            try
                            {
                                GC.KeepAlive(_DocumentsAssociation[pk]);
                            } catch (KeyNotFoundException)
                            {
                                ActionsDocuments n=new ActionsDocuments(this, a, DataMappers);
                                _DocumentsAssociation.Add(n);
                                a.ActionsAssociation.Add(n);
                            }
                        }
                    foreach (Document r in e.RemovedItems)
                        _DocumentsAssociation[new ActionsDocuments.PrimaryKey(Id, r.GetId())].Delete(e.Context);
                };
                _Documents.Saved+=delegate(object s, PersistenceEventArgs e) {
                    _DocumentsAssociation.Save(e.Context);
                };
                _DocumentsAssociation.Deleted+=delegate(object s, PersistenceEventArgs e) {
                    _DocumentsAssociation.Clear();
                };
            }
        }

        /// <summary>Returns the <see cref="Action" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Action Find(Action.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IActionMapper)dataMappers[typeof(Action)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Action" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Action> FindAll(DataMapperCollection dataMappers)
        {
            return ((IActionMapper)dataMappers[typeof(Action)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Action" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Action> FindByEtape(Etape entity, DataMapperCollection dataMappers)
        {
            return ((IActionMapper)dataMappers[typeof(Action)]).FindByEtape(entity, dataMappers);
        }

        /// <summary>Returns the <see cref="Action" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Action> FindByDocuments(Document entity, DataMapperCollection dataMappers)
        {
            return ((IActionMapper)dataMappers[typeof(Action)]).FindByDocuments(entity, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Etape Etape
        {
            get
            {
                Load(true);
                return _Etape;
            }
            set
            {
                _LoadEtape(true);
                if (_Etape!=value)
                {
                    // If _Etape is new, it has been registered for update when being saved for the first time
                    if ((_Etape!=null) && (_Etape.InternalIsNew))
                        _Etape.Saved-=_Etape_Saved;

                    if (_Etape!=null)
                    {
                        if (_Etape.Actions.Contains(this))
                            _Etape.Actions.Remove(this);
                        
                    }
                    if (!value.Actions.Contains(this))
                        value.Actions.Add(this);
                    _Etape=value;

                    // If _Etape is new, its primary key will only be set after being saved for the first time
                    if ((_Etape!=null) && _Etape.InternalIsNew)
                        _Etape.Saved+=_Etape_Saved;
                    else
                        _UpdateEtape();

                    RaisePropertyChanged("Etape");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Document> Documents
        {
            get
            {
                _LoadDocuments(true);
                return new Collection<Document>(_Documents);
            }
        }
        /// <summary />
        internal DomainEntityKeyedCollection<ActionsDocuments> DocumentsAssociation
        {
            get
            {
                _LoadDocuments(true);
                return _DocumentsAssociation;
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String TypeAction
        {
            get
            {
                Load(true);
                return Data.TypeAction;
            }
            set
            {
                if (Data.TypeAction!=value)
                {
                    Data.TypeAction=value;
                    RaisePropertyChanged("TypeAction");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DatePlanification
        {
            get
            {
                Load(true);
                return Data.DatePlanification;
            }
            set
            {
                if (Data.DatePlanification!=value)
                {
                    Data.DatePlanification=value;
                    RaisePropertyChanged("DatePlanification");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DateOuverture
        {
            get
            {
                Load(true);
                return Data.DateOuverture;
            }
            set
            {
                if (Data.DateOuverture!=value)
                {
                    Data.DateOuverture=value;
                    RaisePropertyChanged("DateOuverture");
                }
            }
        }

        /// <summary />
        [StringLengthRule(68)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Acteur
        {
            get
            {
                Load(true);
                return Data.Acteur;
            }
            set
            {
                if (Data.Acteur!=value)
                {
                    Data.Acteur=value;
                    RaisePropertyChanged("Acteur");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? Delai
        {
            get
            {
                Load(true);
                return Data.Delai;
            }
            set
            {
                if (Data.Delai!=value)
                {
                    Data.Delai=value;
                    RaisePropertyChanged("Delai");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.DateTime? DateRealisation
        {
            get
            {
                Load(true);
                return Data.DateRealisation;
            }
            set
            {
                if (Data.DateRealisation!=value)
                {
                    Data.DateRealisation=value;
                    RaisePropertyChanged("DateRealisation");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Statut
        {
            get
            {
                Load(true);
                return Data.Statut;
            }
            set
            {
                if (Data.Statut!=value)
                {
                    Data.Statut=value;
                    RaisePropertyChanged("Statut");
                }
            }
        }

        /// <summary />
        [StringLengthRule(255)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Commentaire
        {
            get
            {
                Load(true);
                return Data.Commentaire;
            }
            set
            {
                if (Data.Commentaire!=value)
                {
                    Data.Commentaire=value;
                    RaisePropertyChanged("Commentaire");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private Etape _Etape;

        /// <summary />
        private DomainEntityKeyedCollection<Document> _Documents;
        /// <summary />
        private DomainEntityKeyedCollection<ActionsDocuments> _DocumentsAssociation;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    internal partial class ActionsDocuments:
        DomainEntity<ActionsDocuments.PrimaryKey, ActionsDocuments.DataTransfer>
    {

        /// <summary />
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        internal partial class PrimaryKey:
            PrimaryKey<PrimaryKey.Key>
        {

            /// <summary>Holds the composite value of the <see cref="ActionsDocuments.PrimaryKey" /> class.</summary>
            internal struct Key
            {

                /// <summary />
#if (!NET_CF)
                [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
                public System.Guid Action_Id;

                /// <summary />
#if (!NET_CF)
                [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
                public System.Guid Document_Id;

                /// <summary>Creates a new instance of the <see cref="ActionsDocuments.PrimaryKey.Key" /> class.</summary>
                public Key(System.Guid action_id, System.Guid document_id)
                {
                    Action_Id=action_id;
                    Document_Id=document_id;
                }

                /// <summary>Returns a string that represents the current <see cref="ActionsDocuments.PrimaryKey" />.</summary>
                public override string ToString()
                {
                    return string.Format(
                        CultureInfo.CurrentCulture,
                        "{0}|{1}",
                        Action_Id,
                        Document_Id
                    );
                }
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey(PrimaryKey.Key key):
                base(key)
            {
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey(Action.PrimaryKey actionKey, Document.PrimaryKey documentKey):
                base(new PrimaryKey.Key(actionKey.Value, documentKey.Value))
            {
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey(Document.PrimaryKey documentKey, Action.PrimaryKey actionKey):
                this(actionKey, documentKey)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(PrimaryKey.Key key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator PrimaryKey.Key(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        internal partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Action_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Document_Id;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public ActionsDocuments():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="ActionsDocuments" /> association entity.</summary>
        public ActionsDocuments(Action action, Document document, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            Debug.Assert(action!=null);
            if (action==null)
                throw new ArgumentNullException("action");
            Debug.Assert(document!=null);
            if (document==null)
                throw new ArgumentNullException("document");

            Action=action;
            Document=document;
        }

        /// <summary>Creates a new instance of the <see cref="ActionsDocuments" /> association entity.</summary>
        public ActionsDocuments(Document document, Action action, DataMapperCollection dataMappers):
            this(action, document, dataMappers)
        {
        }

        /// <summary />
        protected override ActionsDocuments.PrimaryKey CreateId()
        {
            return new ActionsDocuments.PrimaryKey(new ActionsDocuments.PrimaryKey.Key(Data.Action_Id, Data.Document_Id));
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (_Action.InternalIsNew)
                _Action.Save(e.Context);
            if (_Document.InternalIsNew)
                _Document.Save(e.Context);
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Action" /> internal information.</summary>
        private void _UpdateAction()
        {
            Debug.Assert(!_Action.InternalIsNew);
            if (_Action.InternalIsNew)
                throw new InvalidOperationException("_Action has never been saved.");

            {
                System.Guid id=_Action.GetId().Value;
                if (Data.Action_Id!=id)
                    Data.Action_Id=id;
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Document" /> internal information.</summary>
        private void _UpdateDocument()
        {
            Debug.Assert(!_Document.InternalIsNew);
            if (_Document.InternalIsNew)
                throw new InvalidOperationException("_Document has never been saved.");

            {
                System.Guid id=_Document.GetId().Value;
                if (Data.Document_Id!=id)
                    Data.Document_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Action" /> has been saved for the first time.</summary>
        private void _Action_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateAction();
            IsModified=true;
            ((Action)sender).Saved-=_Action_Saved;
        }

        /// <summary>Method called when a <see cref="Document" /> has been saved for the first time.</summary>
        private void _Document_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateDocument();
            IsModified=true;
            ((Document)sender).Saved-=_Document_Saved;
        }

        /// <summary />
        internal ActionsDocuments.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary>Returns the <see cref="ActionsDocuments" /> association instances that are related to the specified entity.</summary>
        public static DomainEntityKeyedCollection<ActionsDocuments> FindByDocument(Document entity, DataMapperCollection dataMappers)
        {
            return ((IActionsDocumentsMapper)dataMappers[typeof(ActionsDocuments)]).FindByDocument(entity, dataMappers);
        }

        /// <summary>Returns the <see cref="ActionsDocuments" /> association instances that are related to the specified entity.</summary>
        public static DomainEntityKeyedCollection<ActionsDocuments> FindByAction(Action entity, DataMapperCollection dataMappers)
        {
            return ((IActionsDocumentsMapper)dataMappers[typeof(ActionsDocuments)]).FindByAction(entity, dataMappers);
        }

        public Action Action
        {
            get
            {
                return _Action;
            }
            private set
            {
                if (_Action!=value)
                {
                    // If _Action is new, it has been registered for update when being saved for the first time
                    if ((_Action!=null) && (_Action.InternalIsNew))
                        _Action.Saved-=_Action_Saved;

                    _Action=value;

                    // If _Action is new, its primary key will only be set after being saved for the first time
                    if ((_Action!=null) && _Action.InternalIsNew)
                        _Action.Saved+=_Action_Saved;
                    else
                        _UpdateAction();
                }
            }
        }

        public Document Document
        {
            get
            {
                return _Document;
            }
            private set
            {
                if (_Document!=value)
                {
                    // If _Document is new, it has been registered for update when being saved for the first time
                    if ((_Document!=null) && (_Document.InternalIsNew))
                        _Document.Saved-=_Document_Saved;

                    _Document=value;

                    // If _Document is new, its primary key will only be set after being saved for the first time
                    if ((_Document!=null) && _Document.InternalIsNew)
                        _Document.Saved+=_Document_Saved;
                    else
                        _UpdateDocument();
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private Action _Action;
        /// <summary />
        private Document _Document;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Document:
        DomainEntity<Document.PrimaryKey, Document.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Document" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Document" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Document.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Document.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Nom;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Donnees;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Fichier;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Document():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Document" /> entity.</summary>
        public Document(DataMapperCollection dataMappers):
            base(dataMappers)
        {
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Document" /> entity with serialized data.</summary>
        protected Document(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadActions(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Actions=null;
            _ActionsAssociation=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);

            _LoadActions(true);
            _ActionsAssociation.Delete(e.Context);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Actions!=null)
                _Actions.Save(e.Context);
        }

        /// <summary />
        protected override Document.PrimaryKey CreateId()
        {
            return new Document.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Document.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadActions(bool lazyload)
        {
            if (_Actions==null)
            {
                if (IsNew)
                {
                    _Actions=new DomainEntityKeyedCollection<Action>();
                    _ActionsAssociation=new DomainEntityKeyedCollection<ActionsDocuments>();
                } else
                {
                    _Actions=(DomainEntityKeyedCollection<Action>)Action.FindByDocuments(this, DataMappers);
                    _ActionsAssociation=(DomainEntityKeyedCollection<ActionsDocuments>)ActionsDocuments.FindByDocument(this, DataMappers);
                }

                _Actions.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        if (!((Action)e.Element).Documents.Contains(this))
                            ((Action)e.Element).Documents.Add(this);
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Action)e.Element).Documents.Contains(this))
                            ((Action)e.Element).Documents.Remove(this);
                        break;
                    }
                };

                _Actions.Saving+=delegate(object s, DomainEntityCollectionSavingEventArgs<Action> e) {
                    foreach (Action a in e.AddedItems)
                        if (!IsNew && !a.InternalIsNew)
                        {
                            ActionsDocuments.PrimaryKey pk=new ActionsDocuments.PrimaryKey(GetId(), a.GetId());
                            try
                            {
                                GC.KeepAlive(_ActionsAssociation[pk]);
                            } catch (KeyNotFoundException)
                            {
                                ActionsDocuments n=new ActionsDocuments(this, a, DataMappers);
                                _ActionsAssociation.Add(n);
                                a.DocumentsAssociation.Add(n);
                            }
                        }
                    foreach (Action r in e.RemovedItems)
                        _ActionsAssociation[new ActionsDocuments.PrimaryKey(Id, r.GetId())].Delete(e.Context);
                };
                _Actions.Saved+=delegate(object s, PersistenceEventArgs e) {
                    _ActionsAssociation.Save(e.Context);
                };
                _ActionsAssociation.Deleted+=delegate(object s, PersistenceEventArgs e) {
                    _ActionsAssociation.Clear();
                };
            }
        }

        /// <summary>Returns the <see cref="Document" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Document Find(Document.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IDocumentMapper)dataMappers[typeof(Document)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Document" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Document> FindAll(DataMapperCollection dataMappers)
        {
            return ((IDocumentMapper)dataMappers[typeof(Document)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Document" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Document> FindByActions(Action entity, DataMapperCollection dataMappers)
        {
            return ((IDocumentMapper)dataMappers[typeof(Document)]).FindByActions(entity, dataMappers);
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Action> Actions
        {
            get
            {
                _LoadActions(true);
                return new Collection<Action>(_Actions);
            }
        }
        /// <summary />
        internal DomainEntityKeyedCollection<ActionsDocuments> ActionsAssociation
        {
            get
            {
                _LoadActions(true);
                return _ActionsAssociation;
            }
        }

        /// <summary />
        [StringLengthRule(127)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Nom
        {
            get
            {
                Load(true);
                return Data.Nom;
            }
            set
            {
                if (Data.Nom!=value)
                {
                    Data.Nom=value;
                    RaisePropertyChanged("Nom");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Donnees
        {
            get
            {
                Load(true);
                return Data.Donnees;
            }
            set
            {
                if (Data.Donnees!=value)
                {
                    Data.Donnees=value;
                    RaisePropertyChanged("Donnees");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Fichier
        {
            get
            {
                Load(true);
                return Data.Fichier;
            }
            set
            {
                if (Data.Fichier!=value)
                {
                    Data.Fichier=value;
                    RaisePropertyChanged("Fichier");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private DomainEntityKeyedCollection<Action> _Actions;
        /// <summary />
        private DomainEntityKeyedCollection<ActionsDocuments> _ActionsAssociation;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Intervention:
        Action
    {

        /// <summary />
        public new partial class DataTransfer:
            Action.DataTransfer
        {

            /// <summary>Creates a new instance of the <see cref="DataTransfer" /> class.</summary>
           public DataTransfer()
           {
               Type="Intervention";
           }

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Equipement_Id;
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Intervention():
            base()
        {
            Data=new DataTransfer();
        }

        /// <summary>Creates a new instance of the <see cref="Intervention" /> entity.</summary>
        public Intervention(Equipement equipement, Etape etape, DataMapperCollection dataMappers):
            base(etape, dataMappers)
        {
            Data=new DataTransfer();
            Equipement=equipement;
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Intervention" /> entity with serialized data.</summary>
        protected Intervention(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadEquipement(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Equipement=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (Equipement!=null)
                Equipement.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Equipement!=null)
                _Equipement.Save(e.Context);
        }

        /// <summary />
        private void _LoadEquipement(bool lazyload)
        {
            if (_Equipement==null)
            {
                if (IsNew)
                    return;

                _Equipement=((IEquipementMapper)DataMappers[typeof(Equipement)]).Find(Data.Equipement_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Equipement" /> internal information.</summary>
        private void _UpdateEquipement()
        {
            Debug.Assert(!_Equipement.InternalIsNew);
            if (_Equipement.InternalIsNew)
                throw new InvalidOperationException("_Equipement has never been saved.");

            {
                System.Guid id=_Equipement.GetId().Value;
                if (Data.Equipement_Id!=id)
                    Data.Equipement_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Equipement" /> has been saved for the first time.</summary>
        private void _Equipement_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateEquipement();
            IsModified=true;
            ((Equipement)sender).Saved-=_Equipement_Saved;
        }

        /// <summary>Returns the <see cref="Intervention" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static new Intervention Find(Action.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IInterventionMapper)dataMappers[typeof(Intervention)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Intervention" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static new IList<Intervention> FindAll(DataMapperCollection dataMappers)
        {
            return ((IInterventionMapper)dataMappers[typeof(Intervention)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Intervention" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Intervention> FindByEquipement(Equipement entity, DataMapperCollection dataMappers)
        {
            return ((IInterventionMapper)dataMappers[typeof(Intervention)]).FindByEquipement(entity, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Equipement Equipement
        {
            get
            {
                Load(true);
                return _Equipement;
            }
            set
            {
                _LoadEquipement(true);
                if (_Equipement!=value)
                {
                    // If _Equipement is new, it has been registered for update when being saved for the first time
                    if ((_Equipement!=null) && (_Equipement.InternalIsNew))
                        _Equipement.Saved-=_Equipement_Saved;

                    if (_Equipement!=null)
                    {
                        if (_Equipement.Interventions.Contains(this))
                            _Equipement.Interventions.Remove(this);
                        
                    }
                    if (!value.Interventions.Contains(this))
                        value.Interventions.Add(this);
                    _Equipement=value;

                    // If _Equipement is new, its primary key will only be set after being saved for the first time
                    if ((_Equipement!=null) && _Equipement.InternalIsNew)
                        _Equipement.Saved+=_Equipement_Saved;
                    else
                        _UpdateEquipement();

                    RaisePropertyChanged("Equipement");
                }
            }
        }

        /// <summary />
        protected new DataTransfer Data
        {
            get
            {
                return (DataTransfer)base.Data;
            }
            set
            {
                base.Data = value;
            }
        }

        /// <summary />
        private Equipement _Equipement;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Adresse:
        DomainEntity<Adresse.PrimaryKey, Adresse.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Adresse" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Adresse" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Adresse.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Adresse.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Voie_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Numero;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Complement;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Adresse():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Adresse" /> entity.</summary>
        public Adresse(Voie voie, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            Voie=voie;
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Adresse" /> entity with serialized data.</summary>
        protected Adresse(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadVoie(lazyLoad);
                _LoadPersonnes(lazyLoad);
                _LoadBranchements(lazyLoad);
                _LoadCompteurs(lazyLoad);
                _LoadLieuxDeService(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Voie=null;
            _Personnes=null;
            _Branchements=null;
            _Compteurs=null;
            _LieuxDeService=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (Voie!=null)
                Voie.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Voie!=null)
                _Voie.Save(e.Context);
        }

        /// <summary />
        protected override Adresse.PrimaryKey CreateId()
        {
            return new Adresse.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Adresse.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadVoie(bool lazyload)
        {
            if (_Voie==null)
            {
                if (IsNew)
                    return;

                _Voie=((IVoieMapper)DataMappers[typeof(Voie)]).Find(Data.Voie_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Voie" /> internal information.</summary>
        private void _UpdateVoie()
        {
            Debug.Assert(!_Voie.InternalIsNew);
            if (_Voie.InternalIsNew)
                throw new InvalidOperationException("_Voie has never been saved.");

            {
                System.Guid id=_Voie.GetId().Value;
                if (Data.Voie_Id!=id)
                    Data.Voie_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Voie" /> has been saved for the first time.</summary>
        private void _Voie_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateVoie();
            IsModified=true;
            ((Voie)sender).Saved-=_Voie_Saved;
        }

        /// <summary />
        private void _LoadPersonnes(bool lazyload)
        {
            if (_Personnes==null)
            {
                if (IsNew)
                    _Personnes=new DomainEntityKeyedCollection<Personne>();
                else
                    _Personnes=(DomainEntityKeyedCollection<Personne>)Personne.FindByAdresse(this, DataMappers);

                _Personnes.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Personne)e.Element).Adresse=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Personne)e.Element).Adresse==this)
                            ((Personne)e.Element).Adresse=null;
                        break;
                    }
                };
            }
        }

        /// <summary />
        private void _LoadBranchements(bool lazyload)
        {
            if (_Branchements==null)
            {
                if (IsNew)
                    _Branchements=new DomainEntityKeyedCollection<Branchement>();
                else
                    _Branchements=(DomainEntityKeyedCollection<Branchement>)Branchement.FindByAdresse(this, DataMappers);

                _Branchements.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Branchement)e.Element).Adresse=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Branchement)e.Element).Adresse==this)
                            ((Branchement)e.Element).Adresse=null;
                        break;
                    }
                };
            }
        }

        /// <summary />
        private void _LoadCompteurs(bool lazyload)
        {
            if (_Compteurs==null)
            {
                if (IsNew)
                    _Compteurs=new DomainEntityKeyedCollection<Compteur>();
                else
                    _Compteurs=(DomainEntityKeyedCollection<Compteur>)Compteur.FindByAdresse(this, DataMappers);

                _Compteurs.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Compteur)e.Element).Adresse=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Compteur)e.Element).Adresse==this)
                            ((Compteur)e.Element).Adresse=null;
                        break;
                    }
                };
            }
        }

        /// <summary />
        private void _LoadLieuxDeService(bool lazyload)
        {
            if (_LieuxDeService==null)
            {
                if (IsNew)
                    _LieuxDeService=new DomainEntityKeyedCollection<LieuDeService>();
                else
                    _LieuxDeService=(DomainEntityKeyedCollection<LieuDeService>)LieuDeService.FindByAdresse(this, DataMappers);

                _LieuxDeService.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((LieuDeService)e.Element).Adresse=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((LieuDeService)e.Element).Adresse==this)
                            ((LieuDeService)e.Element).Adresse=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="Adresse" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Adresse Find(Adresse.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IAdresseMapper)dataMappers[typeof(Adresse)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Adresse" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Adresse> FindAll(DataMapperCollection dataMappers)
        {
            return ((IAdresseMapper)dataMappers[typeof(Adresse)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Adresse" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Adresse> FindByVoie(Voie entity, DataMapperCollection dataMappers)
        {
            return ((IAdresseMapper)dataMappers[typeof(Adresse)]).FindByVoie(entity, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Voie Voie
        {
            get
            {
                Load(true);
                return _Voie;
            }
            set
            {
                _LoadVoie(true);
                if (_Voie!=value)
                {
                    // If _Voie is new, it has been registered for update when being saved for the first time
                    if ((_Voie!=null) && (_Voie.InternalIsNew))
                        _Voie.Saved-=_Voie_Saved;

                    if (_Voie!=null)
                    {
                        if (_Voie.Adresses.Contains(this))
                            _Voie.Adresses.Remove(this);
                        
                    }
                    if (!value.Adresses.Contains(this))
                        value.Adresses.Add(this);
                    _Voie=value;

                    // If _Voie is new, its primary key will only be set after being saved for the first time
                    if ((_Voie!=null) && _Voie.InternalIsNew)
                        _Voie.Saved+=_Voie_Saved;
                    else
                        _UpdateVoie();

                    RaisePropertyChanged("Voie");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Personne> Personnes
        {
            get
            {
                _LoadPersonnes(true);
                return new Collection<Personne>(_Personnes);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Branchement> Branchements
        {
            get
            {
                _LoadBranchements(true);
                return new Collection<Branchement>(_Branchements);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Compteur> Compteurs
        {
            get
            {
                _LoadCompteurs(true);
                return new Collection<Compteur>(_Compteurs);
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<LieuDeService> LieuxDeService
        {
            get
            {
                _LoadLieuxDeService(true);
                return new Collection<LieuDeService>(_LieuxDeService);
            }
        }

        /// <summary />
        [StringLengthRule(7)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Numero
        {
            get
            {
                Load(true);
                return Data.Numero;
            }
            set
            {
                if (Data.Numero!=value)
                {
                    Data.Numero=value;
                    RaisePropertyChanged("Numero");
                }
            }
        }

        /// <summary />
        [StringLengthRule(255)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Complement
        {
            get
            {
                Load(true);
                return Data.Complement;
            }
            set
            {
                if (Data.Complement!=value)
                {
                    Data.Complement=value;
                    RaisePropertyChanged("Complement");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private Voie _Voie;

        /// <summary />
        private DomainEntityKeyedCollection<Personne> _Personnes;

        /// <summary />
        private DomainEntityKeyedCollection<Branchement> _Branchements;

        /// <summary />
        private DomainEntityKeyedCollection<Compteur> _Compteurs;

        /// <summary />
        private DomainEntityKeyedCollection<LieuDeService> _LieuxDeService;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Voie:
        DomainEntity<Voie.PrimaryKey, Voie.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Voie" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Voie" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Voie.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Voie.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Commune_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Nom;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Voie():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Voie" /> entity.</summary>
        public Voie(Commune commune, DataMapperCollection dataMappers):
            base(dataMappers)
        {
            Commune=commune;
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Voie" /> entity with serialized data.</summary>
        protected Voie(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadCommune(lazyLoad);
                _LoadAdresses(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Commune=null;
            _Adresses=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);

            _LoadAdresses(true);
            _Adresses.Delete(e.Context);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);

            if (Commune!=null)
                Commune.Save(e.Context);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Commune!=null)
                _Commune.Save(e.Context);

            if (_Adresses!=null)
                _Adresses.Save(e.Context);
        }

        /// <summary />
        protected override Voie.PrimaryKey CreateId()
        {
            return new Voie.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Voie.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadCommune(bool lazyload)
        {
            if (_Commune==null)
            {
                if (IsNew)
                    return;

                _Commune=((ICommuneMapper)DataMappers[typeof(Commune)]).Find(Data.Commune_Id, DataMappers);
            }
        }

        /// <summary>Updates the internal <see cref="Data" /> with the <see cref="Commune" /> internal information.</summary>
        private void _UpdateCommune()
        {
            Debug.Assert(!_Commune.InternalIsNew);
            if (_Commune.InternalIsNew)
                throw new InvalidOperationException("_Commune has never been saved.");

            {
                System.Guid id=_Commune.GetId().Value;
                if (Data.Commune_Id!=id)
                    Data.Commune_Id=id;
            }
        }

        /// <summary>Method called when a <see cref="Commune" /> has been saved for the first time.</summary>
        private void _Commune_Saved(object sender, PersistenceEventArgs e)
        {
            _UpdateCommune();
            IsModified=true;
            ((Commune)sender).Saved-=_Commune_Saved;
        }

        /// <summary />
        private void _LoadAdresses(bool lazyload)
        {
            if (_Adresses==null)
            {
                if (IsNew)
                    _Adresses=new DomainEntityKeyedCollection<Adresse>();
                else
                    _Adresses=(DomainEntityKeyedCollection<Adresse>)Adresse.FindByVoie(this, DataMappers);

                _Adresses.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Adresse)e.Element).Voie=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Adresse)e.Element).Voie==this)
                            ((Adresse)e.Element).Voie=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="Voie" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Voie Find(Voie.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IVoieMapper)dataMappers[typeof(Voie)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Voie" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Voie> FindAll(DataMapperCollection dataMappers)
        {
            return ((IVoieMapper)dataMappers[typeof(Voie)]).FindAll(dataMappers);
        }

        /// <summary>Returns the <see cref="Voie" /> instances that are related to the specified entity.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Voie> FindByCommune(Commune entity, DataMapperCollection dataMappers)
        {
            return ((IVoieMapper)dataMappers[typeof(Voie)]).FindByCommune(entity, dataMappers);
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Commune Commune
        {
            get
            {
                Load(true);
                return _Commune;
            }
            set
            {
                _LoadCommune(true);
                if (_Commune!=value)
                {
                    // If _Commune is new, it has been registered for update when being saved for the first time
                    if ((_Commune!=null) && (_Commune.InternalIsNew))
                        _Commune.Saved-=_Commune_Saved;

                    if (_Commune!=null)
                    {
                        if (_Commune.Voies.Contains(this))
                            _Commune.Voies.Remove(this);
                        
                    }
                    if (!value.Voies.Contains(this))
                        value.Voies.Add(this);
                    _Commune=value;

                    // If _Commune is new, its primary key will only be set after being saved for the first time
                    if ((_Commune!=null) && _Commune.InternalIsNew)
                        _Commune.Saved+=_Commune_Saved;
                    else
                        _UpdateCommune();

                    RaisePropertyChanged("Commune");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Adresse> Adresses
        {
            get
            {
                _LoadAdresses(true);
                return new Collection<Adresse>(_Adresses);
            }
        }

        /// <summary />
        [StringLengthRule(63)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Nom
        {
            get
            {
                Load(true);
                return Data.Nom;
            }
            set
            {
                if (Data.Nom!=value)
                {
                    Data.Nom=value;
                    RaisePropertyChanged("Nom");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private Commune _Commune;

        /// <summary />
        private DomainEntityKeyedCollection<Adresse> _Adresses;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Commune:
        DomainEntity<Commune.PrimaryKey, Commune.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Commune" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Commune" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Commune.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Commune.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Nom;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String CodePostal;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String CodeInsee;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Boolean Actif;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Commune():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Commune" /> entity.</summary>
        public Commune(DataMapperCollection dataMappers):
            base(dataMappers)
        {
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Commune" /> entity with serialized data.</summary>
        protected Commune(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
                _LoadVoies(lazyLoad);
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

            _Voies=null;
        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);

            _LoadVoies(true);
            _Voies.Delete(e.Context);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);

            if (_Voies!=null)
                _Voies.Save(e.Context);
        }

        /// <summary />
        protected override Commune.PrimaryKey CreateId()
        {
            return new Commune.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Commune.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary />
        private void _LoadVoies(bool lazyload)
        {
            if (_Voies==null)
            {
                if (IsNew)
                    _Voies=new DomainEntityKeyedCollection<Voie>();
                else
                    _Voies=(DomainEntityKeyedCollection<Voie>)Voie.FindByCommune(this, DataMappers);

                _Voies.CollectionChanged+=delegate(object s, CollectionChangeEventArgs e) {
                    switch (e.Action)
                    {
                    case CollectionChangeAction.Add:
                        ((Voie)e.Element).Commune=this;
                        break;
                    case CollectionChangeAction.Remove:
                        if (((Voie)e.Element).Commune==this)
                            ((Voie)e.Element).Commune=null;
                        break;
                    }
                };
            }
        }

        /// <summary>Returns the <see cref="Commune" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Commune Find(Commune.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((ICommuneMapper)dataMappers[typeof(Commune)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Commune" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Commune> FindAll(DataMapperCollection dataMappers)
        {
            return ((ICommuneMapper)dataMappers[typeof(Commune)]).FindAll(dataMappers);
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public Collection<Voie> Voies
        {
            get
            {
                _LoadVoies(true);
                return new Collection<Voie>(_Voies);
            }
        }

        /// <summary />
        [StringLengthRule(63)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Nom
        {
            get
            {
                Load(true);
                return Data.Nom;
            }
            set
            {
                if (Data.Nom!=value)
                {
                    Data.Nom=value;
                    RaisePropertyChanged("Nom");
                }
            }
        }

        /// <summary />
        [StringLengthRule(5)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String CodePostal
        {
            get
            {
                Load(true);
                return Data.CodePostal;
            }
            set
            {
                if (Data.CodePostal!=value)
                {
                    Data.CodePostal=value;
                    RaisePropertyChanged("CodePostal");
                }
            }
        }

        /// <summary />
        [StringLengthRule(5)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String CodeInsee
        {
            get
            {
                Load(true);
                return Data.CodeInsee;
            }
            set
            {
                if (Data.CodeInsee!=value)
                {
                    Data.CodeInsee=value;
                    RaisePropertyChanged("CodeInsee");
                }
            }
        }

        /// <summary />
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.Boolean Actif
        {
            get
            {
                Load(true);
                return Data.Actif;
            }
            set
            {
                if (Data.Actif!=value)
                {
                    Data.Actif=value;
                    RaisePropertyChanged("Actif");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }

        /// <summary />
        private DomainEntityKeyedCollection<Voie> _Voies;
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Bordereau:
        DomainEntity<Bordereau.PrimaryKey, Bordereau.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Bordereau" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Bordereau" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<System.Guid>
        {

            /// <summary>Creates a new instance of the <see cref="Bordereau.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Bordereau.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid id):
                base(id)
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(System.Guid key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator System.Guid(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.Guid Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String CodePharos;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Libelle;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String PrixUnitaire;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Bordereau():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Bordereau" /> entity.</summary>
        public Bordereau(DataMapperCollection dataMappers):
            base(dataMappers)
        {
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Bordereau" /> entity with serialized data.</summary>
        protected Bordereau(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);
        }

        /// <summary />
        protected override Bordereau.PrimaryKey CreateId()
        {
            return new Bordereau.PrimaryKey(Data.Id);
        }

        /// <summary />
        internal Bordereau.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid id)
        {
            Data.Id=id;
        }

        /// <summary>Returns the <see cref="Bordereau" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Bordereau Find(Bordereau.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IBordereauMapper)dataMappers[typeof(Bordereau)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Bordereau" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Bordereau> FindAll(DataMapperCollection dataMappers)
        {
            return ((IBordereauMapper)dataMappers[typeof(Bordereau)]).FindAll(dataMappers);
        }

        /// <summary />
        [NotNullRule]
        [StringLengthRule(12)]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String CodePharos
        {
            get
            {
                Load(true);
                return Data.CodePharos;
            }
            set
            {
                if (Data.CodePharos!=value)
                {
                    Data.CodePharos=value;
                    RaisePropertyChanged("CodePharos");
                }
            }
        }

        /// <summary />
        [NotNullRule]
        [StringLengthRule(127)]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String Libelle
        {
            get
            {
                Load(true);
                return Data.Libelle;
            }
            set
            {
                if (Data.Libelle!=value)
                {
                    Data.Libelle=value;
                    RaisePropertyChanged("Libelle");
                }
            }
        }

        /// <summary />
        [NotNullRule]
#if (!NET_CF)
        [DataObjectField(false, false, false)]
#endif
        public System.String PrixUnitaire
        {
            get
            {
                Load(true);
                return Data.PrixUnitaire;
            }
            set
            {
                if (Data.PrixUnitaire!=value)
                {
                    Data.PrixUnitaire=value;
                    RaisePropertyChanged("PrixUnitaire");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }
    }



    ////////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ////////////////////////////////////////////////////////////////////////////

    public partial class Contact:
        DomainEntity<Contact.PrimaryKey, Contact.DataTransfer>
    {

            /// <summary>Represents a primary key for the <see cref="Contact" /> entity.</summary>
            /// <remarks>Each instance of this class identifies a <see cref="Contact" instance./></remarks>
#if (!NET_CF)
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class PrimaryKey:
            PrimaryKey<PrimaryKey.Key>
        {
            /// <summary>Holds the composite value of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public struct Key
            {

                /// <summary />
#if (!NET_CF)
                [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
                public System.Guid Personne_Id;

                /// <summary />
#if (!NET_CF)
                [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
                public System.Guid LieuDeService_Id;

                /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey.Key" /> class.</summary>
                public Key(System.Guid personne_id, System.Guid lieudeservice_id)
                {
                    Personne_Id=personne_id;
                    LieuDeService_Id=lieudeservice_id;
                }

                /// <summary>Returns a string that represents the current <see cref="Contact.PrimaryKey" />.</summary>
                public override string ToString()
                {
                    return string.Format(
                        CultureInfo.CurrentCulture,
                        "{0}|{1}",
                        Personne_Id,
                        LieuDeService_Id
                    );
                }
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey():
                base()
            {
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey(PrimaryKey.Key key):
                base(key)
            {
            }

            /// <summary>Creates a new instance of the <see cref="Contact.PrimaryKey" /> class.</summary>
            public PrimaryKey(System.Guid personne_id, System.Guid lieudeservice_id):
                base(new PrimaryKey.Key(personne_id, lieudeservice_id))
            {
            }

            /// <summary />
            public static implicit operator PrimaryKey(PrimaryKey.Key key)
            {
                return new PrimaryKey(key);
            }

            /// <summary />
            public static explicit operator PrimaryKey.Key(PrimaryKey key)
            {
                return key.Value;
            }
        }

        /// <summary />
#if (!NET_CF)
        [Serializable]
        [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
#endif
        public partial class DataTransfer:
            IDataTransferObject
        {

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid Personne_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
            [SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
#endif
            public System.Guid LieuDeService_Id;

            /// <summary />
#if (!NET_CF)
            [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
#endif
            public System.String Description;

            /// <summary />
            public object Clone()
            {
                return MemberwiseClone();
            }
        }

        /// <summary>This constructor supports the Salamanca infrastructure and is not intended to be used directly from your code.</summary>
        public Contact():
            base()
        {
        }

        /// <summary>Creates a new instance of the <see cref="Contact" /> entity.</summary>
        public Contact(DataMapperCollection dataMappers):
            base(dataMappers)
        {
        }

#if (!NET_CF)
        /// <summary>Creates a new instance of the <see cref="Contact" /> entity with serialized data.</summary>
        protected Contact(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary />
        public override void Load(bool lazyLoad)
        {
            base.Load(lazyLoad);

            if (!IsNew)
            {
            }
        }

        /// <summary />
        public override void Unload()
        {
            base.Unload();

        }

        /// <summary />
        protected override void OnDeleting(PersistenceEventArgs e)
        {
            base.OnDeleting(e);
        }

        /// <summary />
        protected override void OnSaving(PersistenceEventArgs e)
        {
            base.OnSaving(e);
        }

        /// <summary />
        protected override void OnSaved(PersistenceEventArgs e)
        {
            base.OnSaved(e);
        }

        /// <summary />
        protected override Contact.PrimaryKey CreateId()
        {
            return new Contact.PrimaryKey(Data.Personne_Id, Data.LieuDeService_Id);
        }

        /// <summary />
        internal Contact.PrimaryKey GetId()
        {
            return Id;
        }

        /// <summary />
        internal void SetId(System.Guid personne_id, System.Guid lieudeservice_id)
        {
            Data.Personne_Id=personne_id;
            Data.LieuDeService_Id=lieudeservice_id;
        }

        /// <summary>Returns the <see cref="Contact" /> with the specified key.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, false)]
#endif
        public static Contact Find(Contact.PrimaryKey key, DataMapperCollection dataMappers)
        {
            return ((IContactMapper)dataMappers[typeof(Contact)]).Find(key, dataMappers);
        }

        /// <summary>Returns all the <see cref="Contact" /> instances.</summary>
#if (!NET_CF)
        [DataObjectMethod(DataObjectMethodType.Select, true)]
#endif
        public static IList<Contact> FindAll(DataMapperCollection dataMappers)
        {
            return ((IContactMapper)dataMappers[typeof(Contact)]).FindAll(dataMappers);
        }

        /// <summary />
        [StringLengthRule(255)]
#if (!NET_CF)
        [DataObjectField(false, false, true)]
#endif
        public System.String Description
        {
            get
            {
                Load(true);
                return Data.Description;
            }
            set
            {
                if (Data.Description!=value)
                {
                    Data.Description=value;
                    RaisePropertyChanged("Description");
                }
            }
        }

        /// <summary />
        internal bool InternalIsNew
        {
            get
            {
                return IsNew;
            }
        }
    }
}

